VB6 application vs Java 8u60 for Serial Communication -
i writing java application replace vb6 application. application has poll remote system using 10 byte binary protocol, response 10 byte binary message last byte checksum calculated summing previous bytes.
the problem i'm experiencing high number of errors in java application checksum doesn't match.
the results quite repeatable. vb6 application has virtually no errors, java application has lots. i've checked port settings, same 19200,n,8,1.
in vb6 port set-up serial port set-up follows:
cdtimeout = 0 commport = 1 ctstimeout = 0 dsrtimeout = 0 dtrenable = false eofenable = false handshaking = none inbuffercount = 0 inbuffersize = 1024 index = 0 inputlen = 0 inputmode = cominputmodebinary interval = 1000 name = "cominterfaceunit" nulldiscard = false outbuffersize = 512 parityreplace = "?" rthreshold = 10 rtsenable = false settings = "19200,n,8,1" sthreshold = 0 tag = ""
the javax.comm serialport set-up follows:
baudrate = 19200 closed = false databits = 8 dtr = false flowcontrol = 0 framing = false framingbyte = 0 framingbytereceived = false name = "com1" nativehandle = 324295048 notifymask = 1 parity = 0 rcvthreshold = -1 rcvtimeout = -1 rts = true startbi = false statecd = false statects = false statedsr = false statefe = false stateoe = false statepe = false stateri = false stopbits = 1
in vb6 event handler copies receive bytes byte array , thats java code via serialevent.
java checksum computation:
int intchecksuminpkt = (int)(arychrmsg[response_length -1] & 0xff) ,intcalcchecksum = 0; for( int b=0; b<response_length -1; b++ ) { intcalcchecksum += (int)(arychrmsg[b] & 0xff); } intcalcchecksum &= 0xff; if ( intcalcchecksum == intchecksuminpkt ) { ... }
vb6 checksum code:
intsum = 0 inti = gintinterfaceunitreplystatusoffset gintinterfaceunitreplydata8offset intsum = intsum + cint(gbytinterfaceunitreplyarray(gintcommportindex, inti)) next inti if gbytinterfaceunitreplyarray(gintcommportindex, gintinterfaceunitreplychecksumoffset) = cbyte(intsum , &hff) ' match, 'good' message. blnfunctionvalue = true end if
the actual problem didn't call "enablereceivethreshold".
works now.
Comments
Post a Comment