将数据发送到串行端口时获得否定确认 [英] Getting Negative acknowledge when sending a data to Serial Port

查看:73
本文介绍了将数据发送到串行端口时获得否定确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i正在开发与CRO Machine之一的双向通信,我已经收到了通过机器发送的数据但我在发送数据时出错了发送数据时负面确认的机器..



欢迎提示



i am developing a bidirectional communication with one of CRO Machine , i already received data which send by machine but i have a error when sending a data to the machine that is negative acknowledge while sending data..

ideas welcome

推荐答案

NAK通常是表示你错误地构造了一个校验和 - 所以看看你的代码,找到你是如何构建它的。



值得尝试从设备传递消息你的代码,看看收到的sumcheck和计算的sumcheck值有什么不同。



如果这没有帮助,你需要回到文档并仔细研究如何制定检查 - 有很多方法可以生成,所以我们不能告诉你这样做它会起作用。





确定了。在手册中有一个十六进制的总和a从FN(帧号)到ETX(文本结束)如果我的字符串是02(STX)31(FN 1)测试(它是我的文本)03(ETX)44(CS1)34(CS2)0D(CR) 0A(LF)最后,striing是0231546573740344340D0A,它从31到03,它变为1D4,我的校验和将成为它的最后两位数44和34(即D 34为44)这就是我的校验和的计算方法。抱歉,由于公司政策,我无法发送手册。



这很酷 - 这不是问题。

试试这个:

NAK is normally a sign that you have constructed a checksum wrongly - so look at your code, and find exactly how you are building it.

It's worth trying passing a message from the device through your code to see what the difference in the received sumcheck and the calculated sumcheck values are.

If that doesn't help, you will need to go back to the documentation and look closely at how the check should be worked out - there are a large number of ways it can be generated, so we can't tell you "do this" and it'll work.


"ok got it.in a manual there is a sum of hexa from FN(Frame Number) to ETX(End of Text) If my string is 02(STX)31(FN 1)Test(it is my Text)03(ETX)44(CS1)34(CS2)0D(CR)0A(LF) Finally the striing is 0231546573740344340D0A in it Sum from 31 to 03 it becomes a 1D4 and my checksum will beccome last two digit of it 44 and 34 (i.e 44 for D 34 for 4) This is how my checksum is calcuated. sorry i am not able to send manual due to company policy."

That's cool - it's not a problem.
Try this:
Private Sub button1_Click(sender As Object, e As EventArgs)
	frmMain.ActiveForm.Text = "Hello!"
	Dim inputData As Byte() = New Byte(6) {}
	inputData(0) = &H2
	inputData(1) = &H31
	inputData(2) = CByte("T"C)
	inputData(3) = CByte("e"C)
	inputData(4) = CByte("s"C)
	inputData(5) = CByte("t"C)
	inputData(6) = &H3
	Dim outData As Byte() = CalculateCheck(inputData)
End Sub
Private Shared ToHex As Char() = "0123456789ABCDEF".ToCharArray()
Private Function CalculateCheck(inputData As Byte()) As Byte()
    Dim outData As Byte() = New Byte(inputData.Length + 3) {}
    Dim check As Integer = -inputData(0)
    Dim i As Integer = 0
    For Each b As Byte In inputData
        outData(i) = b
        check += (CInt(b) And &Hff)
        i = i + 1;
    Next
    check = check And &Hff
    outData(i + 0) = CByte(ToHex(check >> 4))
    outData(i + 1) = CByte(ToHex(check And &Hf))
    outData(i + 2) = &Hd
    outData(i + 3) = &Ha
    Return outData
End Function


这篇关于将数据发送到串行端口时获得否定确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆