本文整理汇总了C++中Port::WritePort方法的典型用法代码示例。如果您正苦于以下问题:C++ Port::WritePort方法的具体用法?C++ Port::WritePort怎么用?C++ Port::WritePort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Port
的用法示例。
在下文中一共展示了Port::WritePort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv){
Port* port = new Port("/dev/ttyUSB0");
if(port->OpenPort() == false){
fprintf(stderr, "\n Fail to open port\n");
fprintf(stderr, " CM-730 is used by another program or do not have root privileges.\n\n");
return 0;
}
//dxl power on stuff
//(WriteByte(CM730::ID_CM, CM730::P_DXL_POWER, 1, 0)
unsigned char dxltxpacket[] = {0xFF, 0xFF, 0xC8, 0x04, 0x03, 0x18, 0x01, 0};
dxltxpacket[7] = CalculateChecksum(dxltxpacket);
port->WritePort(dxltxpacket, 8);
printf("Finshed dxl power up. Press enter\n");
getchar();
bool result = Ping(0x14, 0, port);
printf("Ping result: %d\n", result);
}
示例2: main
int main(int argc, char** argv){
Port* port = new Port("/dev/ttyUSB0");
if(port->OpenPort() == false){
fprintf(stderr, "\n Fail to open port\n");
fprintf(stderr, " CM-730 is used by another program or do not have root privileges.\n\n");
return 0;
}
//dxl power on stuff
//(WriteByte(CM730::ID_CM, CM730::P_DXL_POWER, 1, 0)
unsigned char dxltxpacket[] = {0xFF, 0xFF, 0xC8, 0x04, 0x03, 0x18, 0x01, 0};
dxltxpacket[7] = CalculateChecksum(dxltxpacket);
port->WritePort(dxltxpacket, 8);
usleep(2000);
printf("Finshed dxl power up. Press enter\n");
getchar();
Init_to_Pose(port);
getchar();
unsigned char packet[100] = {0, };
usleep(2000);
unsigned char dip_params[3] = {DGAIN, IGAIN, PGAIN};
MakePacket(packet, 0x05, 3, 0x03, 0x1A, dip_params);
port->ClearPort();
port->WritePort(packet, 10);
usleep(2000);
int gainread = 0;
gainread = ReadWord(port, 0x05, 0x1B);
int iread = GetLowByte(gainread);
int pread = GetHighByte(gainread);
printf("i gain: %d\n", iread);
printf("p gain: %d\n", pread);
if(EYES){
int color = MakeColor(230, 0, 230);
// LED packet
packet[0] = 0xFF;
packet[1] = 0xFF;
packet[2] = 0xC8;
packet[3] = 0x05;
packet[4] = 0x03;
packet[5] = 0x1A;
packet[6] = GetLowByte(color);
packet[7] = GetHighByte(color);
packet[8] = CalculateChecksum(packet);
port->ClearPort();
port->WritePort(packet, 9);
usleep(2000);
packet[5] = 0x1C;
packet[8] = CalculateChecksum(packet);
port->ClearPort();
port->WritePort(packet, 9);
usleep(2000);
getchar();
// 0x01C for eye LEDs, 0x1A for head LED
unsigned char txpacket[] = {0xFF, 0xFF, 0xC8, 0x05, 0x03, 0x1C, 0xE0, 0x03, 0};
txpacket[8] = CalculateChecksum(txpacket);
printf("%d \n", txpacket[8]);
int value = port->WritePort(txpacket, 9);
printf("press enter\n");
getchar();
double r[total] = {0, };
double g[total] = {0, };
double b[total] = {0, };
int count;
for(count = 0; count < total; count++){
r[count] = 255*sin(6.28*count/(total/2));
g[count] = 255*sin(6.28*count/(total/11));
b[count] = 255*sin(6.28*count/(total/21));
}
count = 0;
int newcolor;
while(count < total){
port->ClearPort();
newcolor = MakeColor(r[count], g[count], b[count]);
txpacket[6] = GetLowByte(newcolor);
txpacket[7] = GetHighByte(newcolor);
txpacket[8] = 0;
txpacket[8] = CalculateChecksum(txpacket);
port->WritePort(txpacket, 9);
usleep(10000);
count++;
}
//.........这里部分代码省略.........
示例3: main
int main(int argc, char** argv){
Port* port = new Port("/dev/ttyUSB0");
if(port->OpenPort() == false){
fprintf(stderr, "\n Fail to open port\n");
fprintf(stderr, " CM-730 is used by another program or do not have root privileges.\n\n");
return 0;
}
//dxl power on stuff
//(WriteByte(CM730::ID_CM, CM730::P_DXL_POWER, 1, 0)
unsigned char dxltxpacket[] = {0xFF, 0xFF, 0xC8, 0x04, 0x03, 0x18, 0x01, 0};
dxltxpacket[7] = CalculateChecksum(dxltxpacket);
port->WritePort(dxltxpacket, 8);
printf("Finshed dxl power up. Press enter\n");
getchar();
unsigned char rxpacket[MAXNUM_RXPARAM + 10] = {0, };
//unsigned char txpacket[MAXNUM_TXPARAM + 10] = {0, };
//txpacket = {0xFF, 0xFF, id, 4, INST_READ, start address, 2, checksum};
unsigned char txpacketread[] = {0xFF, 0xFF, 0x14, 0x04, 0x02, 0x24, 0x02, 0};
int length = txpacketread[LENGTH] + 4;
txpacketread[length-1] = CalculateChecksum(txpacketread);
// make bulkread packet
int number = 0;
unsigned char BulkReadTxPacket[MAXNUM_TXPARAM + 10] = {0, };
BulkReadTxPacket[0] = 0xFF;
BulkReadTxPacket[1] = 0xFF;
BulkReadTxPacket[ID] = 0xFE;
BulkReadTxPacket[INSTRUCTION] = 0x92;
BulkReadTxPacket[PARAMETER] = 0x0;
if(Ping(0xC8, 0, port)){
BulkReadTxPacket[PARAMETER+3*number+1] = 30; //length
BulkReadTxPacket[PARAMETER+3*number+2] = 0xC8; // ID_CM
BulkReadTxPacket[PARAMETER+3*number+3] = 24; //P_DXL_POWER
number++;
}
if(Ping(70, 0, port)){
BulkReadTxPacket[PARAMETER+3*number+1] = 10; // length
BulkReadTxPacket[PARAMETER+3*number+2] = 0x70; // ID_L_FSR
BulkReadTxPacket[PARAMETER+3*number+3] = 0x1A; // start address P_FSR1_L
number++;
}
if(Ping(0x6F, 0, port)){
BulkReadTxPacket[PARAMETER+3*number+1] = 10; // length
BulkReadTxPacket[PARAMETER+3*number+2] = 0x6F; // id ID_R_FSR
BulkReadTxPacket[PARAMETER+3*number+3] = 0x1A; // start address P_FSR1_L
number++;
}
for(int id = 1; id < 20; id++){ //NUMBER OF JOINTS = 20
BulkReadTxPacket[PARAMETER+3*number+1] = 23; // length
BulkReadTxPacket[PARAMETER+3*number+2] = id; // id
BulkReadTxPacket[PARAMETER+3*number+3] = 26; // start at CCW_COMPLIANCE_MARGIN
number++;
}
BulkReadTxPacket[LENGTH] = (number * 3) + 3;
length = BulkReadTxPacket[LENGTH] + 4;
BulkReadTxPacket[length - 1] = CalculateChecksum(BulkReadTxPacket);
int result = read(port, BulkReadTxPacket, rxpacket);
printf("result: %d\n", result);
int word = MakeWord((int)rxpacket[PARAMETER], (int)rxpacket[PARAMETER + 1]);
printf("Motor position: %d\n\n", word);
printf("Press the ENTER key to close port!\n");
getchar();
port->ClosePort();
}