Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues in Serial read, API bytes Frame data is receving invalid #103

Open
Sarac7t opened this issue Oct 31, 2023 · 0 comments
Open

Issues in Serial read, API bytes Frame data is receving invalid #103

Sarac7t opened this issue Oct 31, 2023 · 0 comments

Comments

@Sarac7t
Copy link

Sarac7t commented Oct 31, 2023

In touch panel controller there is a API frame communication listed below...
we cant able to receive the defined data, I getting error value while receiving as serial.

  1. UART configuration
    Baud Rate : 9600
    Parity : None
    Data Bits : 8
    Stop Bits : 1

  2. Switch Numbering
    In the products variants with fan controller, switch (node) number for fan is 1 and rest of non-dimmable
    node is starting from 2 in horizontal zigzag pattern.

  3. API frame format.
    In API frame structure following is the fixed definition of any command frame
    Every first byte of frame is fixed 0x7B (“{” in ASCII, 123 in decimal).
    Every second byte of frame is ‘command type’ byte, it informs what you need to do with rest
    of the data. This will act as a frame Identifier in the data received from touch panel (response
    frame and event frame)
    Third byte is length of frame. It is 1-byte value (L - 4) where L is total numbers of bytes of
    whole frame.
    Second Last byte is checksum. Checksum is a lower byte of addition of whole individual
    bytes of frame except First byte (Start byte), Second byte (Command type byte),
    Second Last byte (Checksum byte itself) and Last byte is 0x7D.
    Last byte is 0x7D, it is End code to indicate the end of frame. (“}” in ASCII, 125 in
    decimal).
    For Example, consider following frame.

Table 1.1 Frame example 1.
1st Byte 2nd Byte 3rd Byte 4th Byte 5th Byte 6th Byte
0x7B 0x03 0x02 0x05 0x07 0x7D
Start Code Command Length Data Checksum End Code

So the checksum will be lower byte of addition of third byte and fourth byte.
0x02 + 0x05 = 0x07 so we will consider 0x07 as checksum here.

Example 2, consider following frame.
Table 1.2 Frame example 2.

1st Byte 2nd Byte 3rd Byte 4th Byte 5th Byte 6th Byte 7th Byte 8th Byte
0x7B 0x52 0x04 0x02 0xFF 0x14 0x19 0x7D
Start Code Identifier Length Data Data Data Checksum End Code

In this example 2 the checksum will be lower byte of addition of third to sixth byte.
0x04 + 0x02 + 0xFF + 0x14 = 0x0119 so we will consider 0x19 as checksum here.

  1. Command package to update individual single node.
  2. Command
    Following is the command to change the status on touch board for individual single node.
    Table 1.3 Command package for individual single nodes.
    1st 2nd 3rd 4th 5th 6th 7th 8th
    0x7B 0x00 0x04 (0x01 to0xNN) (0x00 for ON and0xFF for OFF) (0x00 to 0x64) CHECKSUM 0x7D

*0xNN depends on number of total nodes
In this frame 4th byte is the node number, 5th byte is On and OFF status and 6th byte is dimming value.
For Fan as well as dimmer, dimming value is in step of 25s.
The touch module should respond an acknowledgement package for this frame Table 1. as described
in the next table. In case of curtain to open the curtain the value of node will be 0x01 to open the
curtain and the value of node will be 0x02 to close the curtain. In both the case the value of status is
0x00. To stop the curtain rotating in between pass the value of status with 0x00.

  1. (Response) Acknowledgement package.
    This acknowledgement package is as response of command has been successfully executed or not.
    This acknowledgement will be transmitted when individual node has been updated. (as described in
    section 1.4). 4th Byte (Node No) is available in hardware version 0x41 onwards.

Status Success
1st 2nd 3rd 4th 5th 6th 7th
0x7B 0x50 0x03 0x01 0x00 CHECKSUM 0x7D

Status Error
1st 2nd 3rd 4th 5th 6th 7th
0x7B 0x50 0x03 (0x01 to0xNN) 0xFF CHECKSUM 0x7D

Can you help me out... I just used to read the data from the Controller , how to read the data properly...

Have used bytes read options but the value is not correct..

I will enclose the code I have used to get serial..

enter code here//
const byte startMarker = 0x7B;
const byte messageLength = 12 ;
byte receivedBytes[messageLength + 1]; //include start marker
boolean newData = false;

void setup() {
 
 Serial.begin(115200);
 Serial2.begin(9600);
// mySerial.setTimeout(200);
 Serial.println("<Arduino is ready>");
}

void loop() {
  recvBytesWithStartMarker();
  showNewData();
}

void recvBytesWithStartMarker() {
  static boolean recvInProgress = false;
  static int ndx = 0;
byte rc;
    
  while (Serial2.available() > 0 && newData == false) {
    rc =Serial2.read();
//    Serial.println(rc);
    if (recvInProgress == true) {
      receivedBytes[ndx] = rc;
      ndx++;
      if (ndx >= messageLength) {
        newData = true;
        recvInProgress = false;
        ndx = 0;
      }
    }
    else {//if (rc == startMarker) {
      recvInProgress = true;
      ndx = 0; // save start marker
      receivedBytes[ndx] = rc;
      ndx++;
    }
  }




}

void showNewData() {
  if (newData == true) {
    Serial.println("This just in ... ");
    for (byte i = 0; i <= messageLength; i++)
    {
      Serial.println(receivedBytes[i], HEX);
    }
    newData = false;
  }
}

OUTPUT:
11:14:22.237 -> 55
11:14:22.237 -> AA
11:14:22.237 -> 3
11:14:22.237 -> 7
11:14:22.237 -> 0
11:14:22.237 -> 5
11:14:22.237 -> 2
11:14:22.237 -> 1
11:14:22.237 -> 0
11:14:22.237 -> 1
11:14:22.237 -> 1
11:14:22.237 -> 13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant