以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]串口字节发送问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=166135) |
-- 作者:YDS -- 发布时间:2021/5/20 11:13:00 -- [求助]串口字节发送问题 Dim ck As String = args(0) Dim sj As String = args(1) If ck > "" Then If Ports.Contains(ck) Then If Ports(ck).IsOpen Then If sj.Split("-").Length > 1 Then Dim Vs() As Byte For i As Integer = 0 To sj.Split("-").Length - 1 Vs(i) = sj.Split("-")(i) Next Ports(ck).Write(Vs, 0, Vs.Length) End If End If End If End If 为什么上面这个自定义函数有问题,下面这个可以正常使用 Dim ck As String = args(0) Dim sj As String = args(1) If ck > "" Then If Ports.Contains(ck) Then If Ports(ck).IsOpen Then If sj.Split("-").Length = 10 Then Dim Vs() As Byte = New Byte() {sj.Split("-")(0),sj.Split("-")(1),sj.Split("-")(2),sj.Split("-")(3),sj.Split("-")(4),sj.Split("-")(5),sj.Split("-")(6),sj.Split("-")(7),sj.Split("-")(8),sj.Split("-")(9)} Ports(ck).Write(Vs, 0, Vs.Length) ElseIf sj.Split("-").Length = 12 Then Dim Vs() As Byte = New Byte() {sj.Split("-")(0),sj.Split("-")(1),sj.Split("-")(2),sj.Split("-")(3),sj.Split("-")(4),sj.Split("-")(5),sj.Split("-")(6),sj.Split("-")(7),sj.Split("-")(8),sj.Split("-")(9),sj.Split("-")(10),sj.Split("-")(11)} Ports(ck).Write(Vs, 0, Vs.Length) End If End If End If End If |
-- 作者:有点蓝 -- 发布时间:2021/5/20 11:34:00 -- Dim ck As String = args(0) Dim sj As String = args(1) If ck > "" Then If Ports.Contains(ck) Then If Ports(ck).IsOpen Then dim ar() as string = sj.Split("-") If ar.Length > 1 Then Dim Vs(ar.Length - 1) As Byte For i As Integer = 0 To ar.Length - 1 Vs(i) = ar(i) Next Ports(ck).Write(Vs, 0, Vs.Length) End If End If End If End If
|
-- 作者:YDS -- 发布时间:2021/5/20 14:35:00 -- 问题解决,谢谢! |