/* MSSSLTD Demonstration only
software serial library is only included
to allow the code to compile in the IDE
*/
[pre]
include <SoftwareSerial.h>SoftwareSerial serial_pm(1,2);void setup() { // put your setup code here, to run once:}void loop() { const uint8_t PACKET_START = 66; const uint8_t PACKET_TERM = 255; const uint8_t PACKET_LENGTH = 24; boolean collectPacket = false; boolean packetAvailable = false; uint8_t packetLength = 0; uint8_t packet[PACKET_LENGTH +1]; //read the serial buffer while( serial_pm.available() ) { char ch = serial_pm.read(); if(!collectPacket) { //start of packet collectPacket = (ch == PACKET_START); packetAvailable = false; packetLength = 0; } if(collectPacket) { //collect packet data packet[packetLength++] = ch; packet[packetLength] = PACKET_TERM; } if(packetLength == PACKET_LENGTH) { //finalise collectPacket = false; packetAvailable = true; } } if(packetAvailable) { Serial.println(F("Packet Available")); }}
[/pre]
« Go back
Powered by Help Desk Software HESK, in partnership with SysAid Technologies