362
edits
Line 56: | Line 56: | ||
To send signals via serial port, you need to send ASCII strings of commands as defined in Magstim's manual. This involves calculating a checksum byte too which is calculated by adding all the bytes in the command, then inverting the first 8 bits bit by bit. For example a command "@050" which is to set the TMS power to 50% needs a checksum byte which can be calculated as amentioned above to be "*". | To send signals via serial port, you need to send ASCII strings of commands as defined in Magstim's manual. This involves calculating a checksum byte too which is calculated by adding all the bytes in the command, then inverting the first 8 bits bit by bit. For example a command "@050" which is to set the TMS power to 50% needs a checksum byte which can be calculated as amentioned above to be "*". | ||
The signal can then be send using: | The signal can then be send using WriteString: | ||
Serial.WriteString "@050*" | Serial.WriteString "@050*" | ||
But in some cases the checksum byte is not type-able (like a file separator for example which is 0X1C in Hex). For that, or for all cases, you can use WriteBytes: | |||
Dim arrData1(4) As Integer | |||
arrData1(0) = &H40 'or you can use the binary value if preferred. for example &B01000000 | |||
arrData1(1) = &H30 | |||
arrData1(2) = &H35 | |||
arrData1(2) = &H30 | |||
arrData1(2) = &H2A 'this is the checksum byte which is "*" in ASCII | |||
Serial.WriteBytes arrData1 | |||
To calculate the checksum byte, I have written this function: | |||
Function CRC(InputString As String) As Integer | Function CRC(InputString As String) As Integer |
edits