guowenxue
2020-08-21 02f4d9518378031c63df7a36c49d8b2eabdaab90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*********************************************************************************
 *      Copyright:  (C) 2013 Guo Wenxue<guowenxue@gmail.com>  
 *                  All rights reserved.
 *
 *       Filename:  test_hh.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(01/28/2013~)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "01/28/2013 03:35:36 PM"
 *                 
 ********************************************************************************/
 
#include <libgen.h>
#include "cp_comport.h"
#define HH_DATAPORT     "/dev/ttySSHHR"
 
/********************************************************************************
 *  Description:
 *   Input Args:
 *  Output Args:
 * Return Value:
 ********************************************************************************/
int main (int argc, char **argv)
{
    int             i;
    COM_PORT        *comport = NULL;
    unsigned char   sbuf[10]={0x02, 0x48, 0x32, 0x03, 0x20, 0x00, 0x00, 0xF6, 0xBE, 0x03};
    unsigned char   rbuf[10];
#if 0
    char            *HH_DATAPORT = NULL;
 
    if(argc != 2)
    {
        printf("Usage: %s [device name]\n", basename(argv[0]));
        return 0;
    }
    HH_DATAPORT = argv[1];
#endif
 
    if( !(comport=comport_init(HH_DATAPORT, 115200, "8N1N")) )
    {
        printf("Initialise comport %s failure\n", HH_DATAPORT);
        return -1;
    }
 
    if(comport_open(comport)<0)
    {
        printf("Open comport %s failure\n", HH_DATAPORT);
        return -1;
    }
 
    if(comport_send(comport, (char *)sbuf, sizeof(sbuf)) < 0)
    {
        printf("Send 10 bytes data to %s failure\n", HH_DATAPORT);
        return -1;
    }
    printf("Send %d bytes data to %s:\n>>", sizeof(sbuf), HH_DATAPORT);
    for(i=0; i<10; i++)
    {
        printf("%02x ", sbuf[i]);
    }
    printf("\n");
 
 
    memset(rbuf, 0, sizeof(rbuf));
    if((i=comport_recv(comport, (char *)rbuf, sizeof(rbuf), 5000)) < 0)
    {
        printf("Receive 10 bytes data to %s failure\n", HH_DATAPORT);
        return -1;
    }
 
    printf("Receive %d bytes data from %s:\n<<", i, HH_DATAPORT);
    for(i=0; i<10; i++)
    {
        printf("%02x ", rbuf[i]);
    }
    printf("\n");
 
    comport_term(comport);
 
    return 0;
} /* ----- End of main() ----- */