11# pyfocas
22
33This project is a barebones reimplementation of the FANUC FOCAS protocol for
4- communicating with a CNC machine.
4+ communicating with a CNC machine.
55
6- It only uses UNIX sockets and sends the proper messages / packets instead of
6+ It only uses UNIX sockets and sends the proper messages / packets instead of
77relying on vendor libraries.
88
99## Sources / Based On
1010
1111This project relies on the reverse engineering of the FANUC FOCAS protocol by
12- [ diohpix] ( https://github.com/diohpix ) .
12+ [ diohpix] ( https://github.com/diohpix ) .
1313The relevant library is [ pyfanuc] ( https://github.com/diohpix/pyfanuc ) .
1414
15- This reimplementation of the protocol is currently the only way of reliably
15+ This reimplementation of the protocol is currently the only way of reliably
1616using FOCAS on a 64bit ARM (aarch64) system as no library for that architecture
1717exists.
1818
@@ -25,11 +25,11 @@ detailing the purpose of the packet.
2525
2626### Header
2727
28- The header looks similar for request and response. A typical header contains
28+ The header looks similar for request and response. A typical header contains
2929the following blocks, with a _ block_ being a part of the header or subpacket:
3030
3131| NAME | Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
32- | --------- | ---------------------- | ------------------ | -------------------- | ----------------------------------- | ---------------------- |
32+ | ------- | -------------------- | ---------------- | ------------------ | --------------------------------- | -------------------- |
3333| PURPOSE | Start of each packet | Server or Client | Open, Close, Other | Length of packet incl. subpackets | Number of subpackets |
3434| LENGTH | 4 bytes | 2 bytes | 2 bytes | 2 bytes | 2 bytes |
3535
@@ -38,28 +38,29 @@ the following blocks, with a _block_ being a part of the header or subpacket:
3838` Packet Origin ` marks if the packet is a request to the FOCAS server (` 00 01 ` )
3939or a response from it (different from ` 00 01 ` ).
4040
41- `` Packet Type `` differentiates the packets between:
41+ ` Packet Type ` differentiates the packets between:
42+
4243- Trying to open a connection to the FOCAS server:
43- - Request: `` 01 01 ` `
44- - Response: `` 01 02 ` `
44+ - Request: ` 01 01 `
45+ - Response: ` 01 02 `
4546- Trying to close the connection:
46- - Request: `` 02 01 ` `
47- - Response: `` 02 02 ` `
47+ - Request: ` 02 01 `
48+ - Response: ` 02 02 `
4849- Trying to execute a generic command:
49- - Request: `` 21 01 ` `
50- - Response: `` 21 02 ` `
50+ - Request: ` 21 01 `
51+ - Response: ` 21 02 `
5152
5253> There are other packet types as can be seen in [ diohpix/pyfanuc] ( https://github.com/diohpix/pyfanuc/blob/da8d9a73148f637276ed1e86b5f04f9965a01b75/README.md#programmtransfer )
53- which are not covered in this project (yet).
54+ > which are not covered in this project (yet).
5455
55- `` Packet Length ` ` contains the total length of bytes coming after it, including
56- the size of the `` Subpacket Count ` ` (2 bytes) and all the subpackets in bytes.
56+ ` Packet Length ` contains the total length of bytes coming after it, including
57+ the size of the ` Subpacket Count ` (2 bytes) and all the subpackets in bytes.
5758
58- > Note that this results in the `` Packet Length ` ` always being larger than the
59- sum of all subpacket's `` Subpacket Length `` by exactly 2 bytes (size of the
60- ` Subpacket Count ` ).
59+ > Note that this results in the ` Packet Length ` always being larger than the
60+ > sum of all subpacket's ` Subpacket Length ` by exactly 2 bytes (size of the
61+ > ` Subpacket Count ` ).
6162
62- `` Subpacket Count ` ` holds the number of subpackets in this packet.
63+ ` Subpacket Count ` holds the number of subpackets in this packet.
6364
6465### Subpacket
6566
@@ -68,12 +69,12 @@ and packing / types.
6869
6970#### Default Payload: 5x 4-Byte INT32
7071
71- The subpackets are always of length `` 1c ` ` / 28 bytes. They each contain three
72- pieces of information about the subpacket totalling 8 bytes followed by a
72+ The subpackets are always of length ` 1c ` / 28 bytes. They each contain three
73+ pieces of information about the subpacket totalling 8 bytes followed by a
7374payload of 20 bytes which can be split into multiple regions.
7475
7576| NAME | Subpacket Length | Control Device | Function | Payload |
76- | --------- | ------------------------- | ---------------- | ------------------------------------------- | ---------------------------------- |
77+ | ------- | ----------------------- | -------------- | ----------------------------------------- | -------------------------------- |
7778| PURPOSE | Length of the subpacket | CNC or PMC | Command to execute or which was executed. | Data transmittable via subpacket |
7879| LENGTH | 2 bytes | 2 bytes | 4 bytes | 20 bytes |
7980
@@ -86,13 +87,13 @@ This needs to be done to create the connection with the FOCAS server.
8687#### Request
8788
8889| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
89- | --------------- | --------------- | ------------- | -------------------------- | -------------------------- |
90+ | ------------- | ------------- | ----------- | ------------------------ | ------------------------ |
9091| ` A0 A0 A0 A0 ` | ` 00 01 ` | ` 01 01 ` | ` 00 02 ` (unclear reason) | ` 00 02 ` (unclear reason) |
9192
9293#### Response
9394
9495| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
95- | --------------- | --------------- | ------------- | -------------------------- | -------------------------- |
96+ | ------------- | ------------- | ----------- | ------------------------ | ------------------------ |
9697| ` A0 A0 A0 A0 ` | ` 00 04 ` | ` 01 02 ` | ` 01 68 ` (unclear reason) | ` 00 08 ` (unclear reason) |
9798
9899The response contains 360 Bytes of (as of yet) unclear subpacket content.
@@ -102,80 +103,80 @@ The response contains 360 Bytes of (as of yet) unclear subpacket content.
102103#### Request
103104
104105| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
105- | --------------- | --------------- | ------------- | --------------- | ----------------- |
106+ | ------------- | ------------- | ----------- | ------------- | --------------- |
106107| ` A0 A0 A0 A0 ` | ` 00 01 ` | ` 21 01 ` | ` 00 1E ` | ` 00 01 ` |
107108
108109With the single subpacket being:
109110
110111| Subpacket Length | Control Device | Function | Payload |
111- | ------------------ | ---------------- | --------------- | --------------- |
112+ | ---------------- | -------------- | ------------- | ------------- |
112113| ` 00 1C ` | ` 00 01 ` | ` 00 01 00 19 ` | 20 times ` 00 ` |
113114
114115#### Response
115116
116117| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
117- | --------------- | --------------- | ------------- | --------------- | ----------------- |
118+ | ------------- | ------------- | ----------- | ------------- | --------------- |
118119| ` A0 A0 A0 A0 ` | ` 00 04 ` | ` 21 02 ` | ` 00 20 ` | ` 00 01 ` |
119120
120121With the single subpacket being:
121122
122- | Subpacket Length | Control Device | Function | Payload |
123- | ------------------ | ---------------- | --------------- | ---------------------------- |
124- | ` 00 1E ` | ` 00 01 ` | ` 00 01 00 19 ` | See _ FOCAS_STATINFO_STRUCT |
123+ | Subpacket Length | Control Device | Function | Payload |
124+ | ---------------- | -------------- | ------------- | --------------------------- |
125+ | ` 00 1E ` | ` 00 01 ` | ` 00 01 00 19 ` | See \ _ FOCAS_STATINFO_STRUCT |
125126
126127### System Info
127128
128129#### Request
129130
130131| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
131- | --------------- | --------------- | ------------- | --------------- | ----------------- |
132+ | ------------- | ------------- | ----------- | ------------- | --------------- |
132133| ` A0 A0 A0 A0 ` | ` 00 01 ` | ` 21 01 ` | ` 00 1E ` | ` 00 01 ` |
133134
134135With the single subpacket being:
135136
136137| Subpacket Length | Control Device | Function | Payload |
137- | ------------------ | ---------------- | --------------- | --------------- |
138+ | ---------------- | -------------- | ------------- | ------------- |
138139| ` 00 1C ` | ` 00 01 ` | ` 00 01 00 18 ` | 20 times ` 00 ` |
139140
140141#### Response
141142
142143| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
143- | --------------- | --------------- | ------------- | --------------- | ----------------- |
144+ | ------------- | ------------- | ----------- | ------------- | --------------- |
144145| ` A0 A0 A0 A0 ` | ` 00 04 ` | ` 21 02 ` | ` 00 24 ` | ` 00 01 ` |
145146
146147With the single subpacket being:
147148
148- | Subpacket Length | Control Device | Function | Payload |
149- | ------------------ | ---------------- | --------------- | --------------------------- |
150- | ` 00 22 ` | ` 00 01 ` | ` 00 01 00 18 ` | See _ FOCAS_SYSINFO_STRUCT |
149+ | Subpacket Length | Control Device | Function | Payload |
150+ | ---------------- | -------------- | ------------- | -------------------------- |
151+ | ` 00 22 ` | ` 00 01 ` | ` 00 01 00 18 ` | See \ _ FOCAS_SYSINFO_STRUCT |
151152
152153### Read Macro
153154
154155#### Request
155156
156157| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
157- | --------------- | --------------- | ------------- | --------------- | ----------------- |
158+ | ------------- | ------------- | ----------- | ------------- | --------------- |
158159| ` A0 A0 A0 A0 ` | ` 00 01 ` | ` 21 01 ` | ` 00 1E ` | ` 00 01 ` |
159160
160161With the single subpacket being:
161162
162163| Subpacket Length | Control Device | Function | Payload |
163- | ------------------ | ---------------- | --------------- | ---------------------------------------- |
164+ | ---------------- | -------------- | ------------- | -------------------------------------- |
164165| ` 00 1C ` | ` 00 01 ` | ` 00 01 00 15 ` | ` 00 00 01 F6 ` ` 00 00 01 F6 ` + 12x ` 00 ` |
165166
166- This reads macro variable #502 (` 01 F6 ` ).
167+ This reads macro variable #502 (` 01 F6 ` ).
167168
168169#### Response
169170
170171| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
171- | --------------- | --------------- | ------------- | --------------- | ----------------- |
172+ | ------------- | ------------- | ----------- | ------------- | --------------- |
172173| ` A0 A0 A0 A0 ` | ` 00 04 ` | ` 21 02 ` | ` 00 1A ` | ` 00 01 ` |
173174
174175With the single subpacket being:
175176
176- | Subpacket Length | Control Device | Function | Payload |
177- | ------------------ | ---------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
178- | ` 00 18 ` | ` 00 01 ` | ` 00 01 00 15 ` | ` 00 00 00 00 ` (Fill) ` 00 00 00 10 ` (#Bytes coming after this) ` 29 7C 1E 00 00 0A 00 06 ` (First 8-Byte Scaled Int) ` 05 F5 E1 00 00 0A 00 08 ` (Second 8-Byte Scaled Int) |
177+ | Subpacket Length | Control Device | Function | Payload |
178+ | ---------------- | -------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
179+ | ` 00 18 ` | ` 00 01 ` | ` 00 01 00 15 ` | ` 00 00 00 00 ` (Fill) ` 00 00 00 10 ` (#Bytes coming after this) ` 29 7C 1E 00 00 0A 00 06 ` (First 8-Byte Scaled Int) ` 05 F5 E1 00 00 0A 00 08 ` (Second 8-Byte Scaled Int) |
179180
180181### Write Macro (Double)
181182
@@ -184,13 +185,13 @@ Writes a macro variable with a double value (not scaled integer)
184185#### Request
185186
186187| Sync Prefix | Packet Origin | Packet Type | Packet Length | Subpacket Count |
187- | --------------- | --------------- | ------------- | --------------- | ----------------- |
188+ | ------------- | ------------- | ----------- | ------------- | --------------- |
188189| ` A0 A0 A0 A0 ` | ` 00 01 ` | ` 21 01 ` | ` 00 38 ` | ` 00 01 ` |
189190
190191With the single subpacket being:
191192
192193| Subpacket Length | Control Device | Function | Payload |
193- | ------------------ | ---------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
194+ | ---------------- | -------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
194195| ` 00 24 ` | ` 00 01 ` | ` 00 01 00 A8 ` | ` 00 00 01 F6 ` (Var. 502) ` 00 ` (12x Filling Bytes) ` 00 00 00 08 ` (#Bytes coming after this) ` 40 59 00 00 00 00 00 00 ` (Value as double) |
195196
196- This writes 100.0 to #502 .
197+ This writes 100.0 to #502 .
0 commit comments