

Since Right_String is not destructive, I needed a way to remove the checksum hex from the rest of the response, so I was trying something with the garbage = line, but it isn't working at all. I can copy the last bit from the return string, so that I can calculate that against what the checksum SHOULD be, by using Right_String. Garbage = REMOVE_STRING(sProjInput,locatedCkSum,(length_string(startgarbage)-1)) //trashes last value, leaving cmd LocatedCkSum = RIGHT_STRING(sProjInput,1) //copies last value

LOCAL_VAR CHAR sProjInput //copy data into string variableĪCTIVE (FIND_STRING(sProjInput,"$22",1)): //If an input response is sent In my data event, I am looking for the response string(s) from the projector: I am trying to use the same checksum function as before, since it calcs the same, but I'm getting stuck on a few parts. It is calculated the same way, but with different starting hex bytes. I've got just about everything together to make this work, but there is one more piece I'm unsure of - the protocol guide states that when the projector sends a reply, it also calculates its own checksum, which is different than the checksum I am sending. Note: ckSum has been changed to an integer to prevent any wrap around issues. Local_var integer ckSum //change back to stackįor(i=1 i<=length_string(sStringValue) i++) Local_var char ckSum //change back to stackĬkSum = 0 //reset ckSum - remove when changed back to stackĪs TurnipTruck said it might be nice to use a binary and to just get the lower 8 bits: Local_var integer i //change back to stack If you're going to keep ckSum as a local so that you can monitor it you will need to reset it back to 0 before you start using it:ĭEFINE_FUNCTION CHAR fcnCheckSum(char sStringValue) I gets set to 1 every time in your for loop initialization, however ckSum will already be holding its previous value every time the function is entered.
#Nec checksum calculator code
When you changed those stack_var's to locals it important to remember that local_var's will hold their value when the code exits scope. I understand that the function is returning an integer, which is what I want, since the idea here is to simply add the hex values together to come up with the checksum. In the hope that I could simply refer to the constant when doing the SEND_STRING. Can I not debug these?ĭEFINE_FUNCTION INTEGER fcnCheckSum(char sStringValue)įor(i=1 i<=length_string(sStringValue) i++) Is it simply running too fast for me to see, since the stack_var resets itself to 0 when it's done? I found it to be odd that when I dragged the stack_vars into the debug window, the value and display types never populated.

SEND_STRING dvPROJ, "cProjOn,fcnCheckSum(cProjOn)"īut when trying to debug, I don't see the stack_var i, to indicate that the for loop ever ran. When I want to send a command that needs a checksum calculated, what is the proper syntax? I was trying it like this: Can I ask a question on the checksum functions?
