// uart_SendCmd.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "windows.h" #include "PACSDK.h" #include "stdlib.h" int main(int argc, char* argv[]) { if(argc < 3) { printf("ICPDAS (R) SDK Demo for XP-8000\n\n"); printf("usage: uart_SendCmd ConnectionString Slot|Address \n\n"); printf("where\n"); printf(" ConnectionString:\n"); printf(" - the COM port, baud rate,\n"); printf(" parity bits, data bits, and stop bits.\n\n"); printf(" Slot:\n"); printf(" - number of slot for local modules\n"); printf(" Address:\n"); printf(" - number of slot for remote modules\n"); } else { char result[4096]; HANDLE hPort; BOOL err; char strErr[32]; memset(result, 0, 4096); hPort = uart_Open(argv[1]); if(hPort == INVALID_HANDLE_VALUE) { pac_GetErrorMessage(pac_GetLastError(), strErr); printf("Open Error: %s. The error code is %x\n", strErr, pac_GetLastError()); return 0; } if(argv[1][3] == '1') { pac_ChangeSlot((BYTE)atoi(argv[2])); err = uart_SendCmd(hPort, "$00M", result); } else { char cmd[32]; sprintf(cmd, "$%02xM", atoi(argv[2])); err = uart_SendCmd(hPort, cmd, result); } if(err == FALSE) { pac_GetErrorMessage(pac_GetLastError(), strErr); printf("Send Cmd Error: %s. The error code is %x\n", strErr, pac_GetLastError()); return 0; } err = uart_Close(hPort); if(err == FALSE) { pac_GetErrorMessage(pac_GetLastError(), strErr); printf("Close Error: %s. The error code is %x\n", strErr, pac_GetLastError()); return 0; } printf(result); } return 0; }