author | lbessard |
Mon, 28 May 2007 18:08:24 +0200 | |
changeset 205 | dac0f9b4e3f8 |
parent 175 | e255529b6f7d |
child 255 | 7b9f36dbfe5f |
permissions | -rw-r--r-- |
145
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
1 |
/************************************************************************** |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
2 |
CanFestival3 win32 port example |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
3 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
4 |
This sample demonstrates CanFestival usage with Win32 |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
5 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
6 |
Program implements master node. It starts CANOpen slave node, modifies OD, |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
7 |
performs SDO reads and prints some slave node information. |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
8 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
9 |
Usage: |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
10 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
11 |
win32test <node_id> |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
12 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
13 |
where node_id is node ID in decimal format |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
14 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
15 |
You should have CanFestival-3.dll CAN-uVCCM.dll in the search path to run this sample. |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
16 |
Code will work with non-UNICODE CanFestival-3.dll CAN-uVCCM.dll libraries. |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
17 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
18 |
Sample can work on other platdorms as well. |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
19 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
20 |
Copyright (C) 2007 Leonid Tochinski (ltochinski AT chattenassociates DOT com) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
21 |
***************************************************************************/ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
22 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
23 |
#include <stdio.h> |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
24 |
#include <stdlib.h> |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
25 |
#include "win32test.h" |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
26 |
#include "canfestival.h" |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
27 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
28 |
#ifdef WIN32 |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
29 |
#define sleep_proc(ms) Sleep(ms) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
30 |
#define uptime_ms_proc() GetTickCount() |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
31 |
#else |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
32 |
#include <time.h> |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
33 |
#define sleep_proc(ms) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
34 |
#define uptime_ms_proc (1000*(time()%86400)) // TOD |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
35 |
#endif |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
36 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
37 |
UNS8 GetChangeStateResults(UNS8 node_id, UNS8 expected_state, unsigned long timeout_ms) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
38 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
39 |
unsigned long start_time = 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
40 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
41 |
// reset nodes state |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
42 |
win32test_Data.NMTable[node_id] = Unknown_state; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
43 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
44 |
// request node state |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
45 |
masterRequestNodeState(&win32test_Data, node_id); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
46 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
47 |
start_time = uptime_ms_proc(); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
48 |
while(uptime_ms_proc() - start_time < timeout_ms) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
49 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
50 |
if (getNodeState(&win32test_Data, node_id) == expected_state) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
51 |
return 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
52 |
sleep_proc(1); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
53 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
54 |
return 0xFF; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
55 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
56 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
57 |
UNS8 ReadSDO(UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, void* data, UNS8* size) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
58 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
59 |
UNS32 abortCode = 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
60 |
UNS8 res = SDO_UPLOAD_IN_PROGRESS; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
61 |
// Read SDO |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
62 |
UNS8 err = readNetworkDict (&win32test_Data, nodeId, index, subIndex, dataType); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
63 |
if (err) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
64 |
return 0xFF; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
65 |
for(;;) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
66 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
67 |
res = getReadResultNetworkDict (&win32test_Data, nodeId, data, size, &abortCode); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
68 |
if (res != SDO_UPLOAD_IN_PROGRESS) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
69 |
break; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
70 |
sleep_proc(1); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
71 |
continue; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
72 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
73 |
closeSDOtransfer(&win32test_Data, nodeId, SDO_CLIENT); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
74 |
if (res == SDO_FINISHED) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
75 |
return 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
76 |
return 0xFF; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
77 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
78 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
79 |
int main(int argc, char *argv[]) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
80 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
81 |
UNS8 node_id = 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
82 |
s_BOARD MasterBoard = {"1", "125K"}; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
83 |
char* dll_file_name; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
84 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
85 |
/* process command line arguments */ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
86 |
if (argc < 2) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
87 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
88 |
printf("USAGE: win32test node_id [dll_file_name]\n"); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
89 |
return 1; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
90 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
91 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
92 |
node_id = atoi(argv[1]); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
93 |
if (node_id < 2 || node_id > 127) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
94 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
95 |
printf("ERROR: node_id shoule be >=2 and <= 127\n"); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
96 |
return 1; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
97 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
98 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
99 |
if (argc > 2) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
100 |
dll_file_name = argv[2]; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
101 |
else |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
102 |
dll_file_name = "can_uvccm_win32.dll"; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
103 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
104 |
// load can driver |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
105 |
if (!LoadCanDriver(dll_file_name)) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
106 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
107 |
printf("ERROR: could not load diver %s\n", dll_file_name); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
108 |
return 1; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
109 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
110 |
|
149 | 111 |
if (canOpen(&MasterBoard,&win32test_Data)) |
145
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
112 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
113 |
/* Defining the node Id */ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
114 |
setNodeId(&win32test_Data, 0x01); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
115 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
116 |
/* init */ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
117 |
setState(&win32test_Data, Initialisation); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
118 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
119 |
/****************************** START *******************************/ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
120 |
/* Put the master in operational mode */ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
121 |
setState(&win32test_Data, Operational); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
122 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
123 |
/* Ask slave node to go in operational mode */ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
124 |
masterSendNMTstateChange (&win32test_Data, 0, NMT_Start_Node); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
125 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
126 |
printf("\nStarting node %d (%xh) ...\n",(int)node_id,(int)node_id); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
127 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
128 |
/* wait untill mode will switch to operational state*/ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
129 |
if (GetChangeStateResults(node_id, Operational, 3000) != 0xFF) |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
130 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
131 |
/* modify Client SDO 1 Parameter */ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
132 |
UNS32 COB_ID_Client_to_Server_Transmit_SDO = 0x600 + node_id; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
133 |
UNS32 COB_ID_Server_to_Client_Receive_SDO = 0x580 + node_id; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
134 |
UNS32 Node_ID_of_the_SDO_Server = node_id; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
135 |
UNS8 ExpectedSize = sizeof (UNS32); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
136 |
|
175
e255529b6f7d
Added writeLocalDict and readLocalDict, that have to be called from application instead of getODEntry and setODEntry. Fix potential endianization problem.
etisserant
parents:
149
diff
changeset
|
137 |
if (OD_SUCCESSFUL == writeLocalDict(&win32test_Data, 0x1280, 1, &COB_ID_Client_to_Server_Transmit_SDO, &ExpectedSize, RW) |
e255529b6f7d
Added writeLocalDict and readLocalDict, that have to be called from application instead of getODEntry and setODEntry. Fix potential endianization problem.
etisserant
parents:
149
diff
changeset
|
138 |
&& OD_SUCCESSFUL == writeLocalDict(&win32test_Data, 0x1280, 2, &COB_ID_Server_to_Client_Receive_SDO, &ExpectedSize, RW) |
e255529b6f7d
Added writeLocalDict and readLocalDict, that have to be called from application instead of getODEntry and setODEntry. Fix potential endianization problem.
etisserant
parents:
149
diff
changeset
|
139 |
&& OD_SUCCESSFUL == writeLocalDict(&win32test_Data, 0x1280, 3, &Node_ID_of_the_SDO_Server, &ExpectedSize, RW)) |
145
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
140 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
141 |
UNS32 dev_type = 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
142 |
char device_name[64]=""; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
143 |
char hw_ver[64]=""; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
144 |
char sw_ver[64]=""; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
145 |
UNS32 vendor_id = 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
146 |
UNS32 prod_code = 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
147 |
UNS32 ser_num = 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
148 |
UNS8 size; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
149 |
UNS8 res; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
150 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
151 |
printf("\nnode_id: %d (%xh) info\n",(int)node_id,(int)node_id); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
152 |
printf("********************************************\n"); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
153 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
154 |
size = sizeof (dev_type); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
155 |
res = ReadSDO(node_id, 0x1000, 0, uint32, &dev_type, &size); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
156 |
printf("device type: %d\n",dev_type & 0xFFFF); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
157 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
158 |
size = sizeof (device_name); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
159 |
res = ReadSDO(node_id, 0x1008, 0, visible_string, device_name, &size); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
160 |
printf("device name: %s\n",device_name); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
161 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
162 |
size = sizeof (hw_ver); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
163 |
res = ReadSDO(node_id, 0x1009, 0, visible_string, hw_ver, &size); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
164 |
printf("HW version: %s\n",hw_ver); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
165 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
166 |
size = sizeof (sw_ver); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
167 |
res = ReadSDO(node_id, 0x100A, 0, visible_string, sw_ver, &size); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
168 |
printf("SW version: %s\n",sw_ver); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
169 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
170 |
size = sizeof (vendor_id); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
171 |
res = ReadSDO(node_id, 0x1018, 1, uint32, &vendor_id, &size); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
172 |
printf("vendor id: %d\n",vendor_id); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
173 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
174 |
size = sizeof (prod_code); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
175 |
res = ReadSDO(node_id, 0x1018, 2, uint32, &prod_code, &size); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
176 |
printf("product code: %d\n",prod_code); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
177 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
178 |
size = sizeof (ser_num); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
179 |
res = ReadSDO(node_id, 0x1018, 4, uint32, &ser_num, &size); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
180 |
printf("serial number: %d\n",ser_num); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
181 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
182 |
printf("********************************************\n"); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
183 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
184 |
else |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
185 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
186 |
printf("ERROR: Object dictionary access failed\n"); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
187 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
188 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
189 |
else |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
190 |
{ |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
191 |
printf("ERROR: node_id %d (%xh) is not responding\n",(int)node_id,(int)node_id); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
192 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
193 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
194 |
masterSendNMTstateChange (&win32test_Data, 0x02, NMT_Stop_Node); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
195 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
196 |
setState(&win32test_Data, Stopped); |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
197 |
|
149 | 198 |
canClose(&win32test_Data); |
145
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
199 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
200 |
return 0; |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
201 |
} |
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
202 |
|
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
diff
changeset
|
203 |