【发布时间】:2021-05-09 17:03:42
【问题描述】:
如果我使用VB6通过WriteFile(串行通信)发送字符串(字符)a,接收端将得到97(读取字节),这是a的十进制值。
现在我希望接收方获取 0-255 的字节值。
很容易得到一些结果,比如:
发送字符串a,获取字节97。发送字符串z,获取字节122。但是如何让receive获得字节值0或1?
我怎样才能意识到这一点?我找到了 vb6 cbyte 函数,但它似乎无法正常工作。谢谢。
这是我当前的代码:
发送方(vb6):
'this send the character "a"
call send_string(handle, "a")
Sub send_string(ByVal handle_connect As Long, ByVal s As String)
WriteComm handle_connect, StrConv(s, vbFromUnicode)
End Sub
Function WriteComm(ByVal hComm As Long, BytesBuffer() As Byte) As Long
Dim dwBytesWrite
If SafeArrayGetDim(BytesBuffer) = 0 Then Exit Function
WriteFile hComm, BytesBuffer(0), UBound(BytesBuffer) + 1, dwBytesWrite, 0
WriteComm = dwBytesWrite
End Function
接收方(arduino):
void setup() {
Serial.begin(115200);
}
void loop() {
if (Serial.available()) {
Serial.println(Serial.read()); //this print the byte received
}
}
【问题讨论】:
-
请编辑您的问题以包含您正在使用的相关代码。谢谢
-
@StayOnTarget 谢谢你的回复,我做到了。
标签: vb6