全部博文(396)
分类: 嵌入式
2018-07-13 17:24:09
这里以图2为例子, 进行说明
假设主节点为01,待读取节点为0x1b
读取的数据是
UNS8 g_upgrade_buf_appbin[258]="bbbcccddd111222333444555666777888999AAA\0";
/* Mapped at index 0x2007, subindex 0x01 */
发送:
A0 07 20 01 10 00 00 00
data[0] = (5 << 5) | SDO_BCS_INITIATE_UPLOAD_REQUEST;
data[1] = index & 0xFF; /* LSB */
data[2] = (index >> 8) & 0xFF; /* MSB */
data[3] = subIndex;
data[4] = SDO_BLOCK_SIZE;
for (i = 5 ; i < 8 ; i++)
data[i] = 0;
接收:
C2 07 20 01 27 00 00 00
data[0] = (6 << 5) | (1 << 1) | SDO_BSS_INITIATE_UPLOAD_RESPONSE;
data[1] = index & 0xFF; /* LSB */
data[2] = (index >> 8) & 0xFF; /* MSB */
data[3] = subIndex;
data[4] = (UNS8) nbBytes;
data[5] = (UNS8) (nbBytes >> 8);
data[6] = (UNS8) (nbBytes >> 16);
data[7] = (UNS8) (nbBytes >> 24);
发送:
A3 00 00 00 00 00 00 00
data[0] = (5 << 5) | SDO_BCS_START_UPLOAD;
for (i = 1 ; i < 8 ; i++)
data[i] = 0;
接收:
01 62 62 62 63 63 63 64
02 64 64 31 31 31 32 32
03 32 33 33 33 34 34 34
04 35 35 35 36 36 36 37
05 37 37 38 38 38 39 39
86 39 41 41 41 00 00 00
data[0] = SeqNo;
err = lineToSDO(d, line, 7, data + 1);
发送:
A2 06 10 00 00 00 00 00
data[0] = (5 << 5) | SDO_BCS_UPLOAD_RESPONSE;
data[1] = d->transfers[line].seqno;
data[2] = SDO_BLOCK_SIZE;
data[3] = data[4] = data[5] = data[6] = data[7] = 0;
接收:
Cd 00 00 00 00 00 00 00
data[0] = (6 << 5) | ((d->transfers[line].endfield) << 2)|SDO_BCS_END_DOWNLOAD_REQUEST;
for (i = 1 ; i < 8 ; i++)
data[i] = 0;
发送:
A1 00 00 00 00 00 00 00
data[0] = (5 << 5) | SDO_BCS_END_UPLOAD_REQUEST;
for (i = 1 ; i < 8 ; i++)
data[i] = 0;
图3
这里以图3为例子, 进行说明
假设主节点为01,待写入节点为0x1b
假如待写入的数据是
UUNS8 write_net_block_buf[] = "0123456789aaabbbcccddd\0";
/* Mapped at index 0x2007, subindex 0x01 */
发送:
C2 07 20 01 18 00 00 00
buf[0] = (6 << 5) | (1 << 1 ); /* CCS = 6 , CC = 0 , S = 1 , CS = 0 */
buf[1] = index & 0xFF; /* LSB */
buf[2] = (index >> 8) & 0xFF; /* MSB */
buf[3] = subIndex;
for (i = 0 ; i < 4 ; i++)
buf[i+4] = (UNS8)((count >> (i<<3))); /* i*8 */
接收:
A0 07 20 01 10 00 00 00
data[0] = (5 << 5) | SDO_BSS_INITIATE_DOWNLOAD_RESPONSE;
data[1] = (UNS8) index; /* LSB */
data[2] = (UNS8) (index >> 8); /* MSB */
data[3] = subIndex;
data[4] = SDO_BLOCK_SIZE;
data[5] = data[6] = data[7] = 0;
发送:
01 30 31 32 33 34 35 36
02 37 38 39 61 61 61 62
03 62 62 63 63 63 64 65
84 64 00 00 00 00 00 00
当实际发送字节大于7个字节时:
data[0] = SeqNo;
err = lineToSDO(d, line, 7, data + 1);
剩余的小于7个字节的发送时:
data[0] = 0x80 | SeqNo;
err = lineToSDO(d, line, nbBytes, data + 1); //实际的剩余字节
for (i = nbBytes + 1 ; i < 8 ; i++) //多余的空间填0
data[i] = 0;
接收:
A2 04 10 00 00 00 00 00
data[0] = (5 << 5) | SDO_BSS_DOWNLOAD_RESPONSE;
data[1] = d->transfers[line].seqno;
data[2] = SDO_BLOCK_SIZE;
data[3] = data[4] = data[5] = data[6] = data[7] = 0;
发送:
D1 00 00 00 00 00 00 00
data[0] = (6 << 5) | ((d->transfers[line].endfield) << 2) | SDO_BCS_END_DOWNLOAD_REQUEST;
for (i = 1 ; i < 8 ; i++)
data[i] = 0;
将传输结构体里面的数据拷贝到数据字典里,并复位SDO传输!
接收:
A1 00 00 00 00 00 00 00
data[0] = (5 << 5) | SDO_BSS_END_DOWNLOAD_RESPONSE;
for (i = 1 ; i < 8 ; i++)
data[i] = 0;