Each digital output module is represented under the cfnet-fs mount point by a directory at {mount-point}/digital-output/{module_address}/
$ tree -L 2 /tmp/cfnet-fs/digital-output/ /tmp/cfnet-fs/digital-output/ ├── 0 │ ├── channel │ ├── state.bin │ └── state.txt ├── 1 │ ├── channel │ ├── state.bin │ └── state.txt ...
Each digital output module has 2 state files:
state.txt: The state of all 16 channels as an ASCII string of 1s and 0s.state.bin: The state of all 16 channels as a 16-bit, unsigned binary number.Writing to either of the state files will change the state of all digital output channels.
Text files are convenient when the state is directly obtained from or displayed to users, for example, in shell scripts. Binary files are more convenient when the state requires additional processing such as math and logic.
$ echo 1111111111111111 > /tmp/cfnet-fs/digital-output/0/state.txt $ echo 0000000000000000 > /tmp/cfnet-fs/digital-output/0/state.txt
const string DIGITAL_OUTPUT_0 = "/tmp/cfnet-fs/digital-output/0/state.txt"; while (true) { File.WriteAllText(DIGITAL_OUTPUT_0, "1111111111111111"); Thread.Sleep(500); File.WriteAllText(DIGITAL_OUTPUT_0, "0000000000000000 "); Thread.Sleep(500); }
const string DIGITAL_OUTPUT_0 = "/tmp/cfnet-fs/digital-output/0/state.bin"; while (true) { File.WriteAllBytes(DIGITAL_OUTPUT_0, [0xFF, 0xFF]); Thread.Sleep(500); File.WriteAllBytes(DIGITAL_OUTPUT_0, [0x00, 0x00]); Thread.Sleep(500); }
import time DIGITAL_OUTPUT_0 = "/tmp/cfnet-fs/digital-output/0/state.txt" while True: open(DIGITAL_OUTPUT_0 , "w").write("1111111111111111") time.sleep(0.5) open(DIGITAL_OUTPUT_0 , "w").write("0000000000000000") time.sleep(0.5)
import time DIGITAL_OUTPUT_0 = "/tmp/cfnet-fs/digital-output/0/state.bin" while True: open(DIGITAL_OUTPUT_0 , "w").write(b'\xFF\xFF') time.sleep(0.5) open(DIGITAL_OUTPUT_0 , "w").write(b'\x00\x00') time.sleep(0.5)
#include <stdio.h> #include <unistd.h> #define PATH_DIGITAL_OUTPUT_0 "/tmp/cfnet-fs/digital-output/0/state.txt" static void write_text(const char *path, const char *str) { FILE *f = fopen(path, "w"); fputs(str, f); fclose(f); } int main(void) { while (1) { write_text(PATH_DIGITAL_OUTPUT_0, "1111111111111111"); usleep(500000); write_text(PATH_DIGITAL_OUTPUT_0, "0000000000000000"); usleep(500000); } }
#include <stdio.h> #include <unistd.h> #define PATH_DIGITAL_OUTPUT_0 "/tmp/cfnet-fs/digital-output/0/state.bin" static void write_bytes(const char *path, const unsigned char *data, int size) { FILE *f = fopen(path, "wb"); fwrite(data, 1, size, f); fclose(f); } int main(void) { while (1) { write_bytes(PATH_DIGITAL_OUTPUT_0, (unsigned char[]){255, 255}, 2); usleep(500000); write_bytes(PATH_DIGITAL_OUTPUT_0, (unsigned char[]){0, 0}, 2); usleep(500000); } }
Each digital output channel is represented under the cfnet-fs mount point by a directory at {mount-point}/digital-output/{module_address}/channel/{channel_address}/
$ tree /tmp/cfnet-fs/digital-output/0/ /tmp/cfnet-fs/digital-output/0/ ├── channel │ ├── 0 │ │ ├── state.bin │ │ └── state.txt │ ├── 1 │ │ ├── state.bin │ │ └── state.txt │ ...
Each digital output channel has 2 state files:
state.txt: The state of the digital output channel as an ASCII 1 or 0.state.bin: The state of the digital output channel as a single binary byte: 0: Off. Non-Zero: On.Writing to either of the state files will change the state of the digital output channel.
Text files are convenient when the state is directly obtained from or displayed to users, for example, in shell scripts. Binary files are more convenient when the state requires additional processing such as math and logic.
$ echo 1 > /tmp/cfnet-fs/digital-output/0/channel/3/state.txt $ echo 0 > /tmp/cfnet-fs/digital-output/0/channel/3/state.txt
const string DIGITAL_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/digital-output/0/channel/3/state.txt"; while (true) { File.WriteAllText(DIGITAL_OUTPUT_0_CHANNEL_3 , "1"); Thread.Sleep(500); File.WriteAllText(DIGITAL_OUTPUT_0_CHANNEL_3 , "0"); Thread.Sleep(500); }
const string DIGITAL_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/digital-output/0/channel/3/state.bin"; while (true) { File.WriteAllBytes(DIGITAL_OUTPUT_0_CHANNEL_3 , [ 1 ]); Thread.Sleep(500); File.WriteAllBytes(DIGITAL_OUTPUT_0_CHANNEL_3 , [ 0 ]); Thread.Sleep(500); }
import time DIGITAL_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/digital-output/0/channel/3/state.txt" while True: open(DIGITAL_OUTPUT_0_CHANNEL_3 , "w").write("1") time.sleep(0.5) open(DIGITAL_OUTPUT_0_CHANNEL_3 , "w").write("0") time.sleep(0.5)
import time DIGITAL_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/digital-output/0/channel/3/state.bin" while True: open(DIGITAL_OUTPUT_0_CHANNEL_3 , "wb").write(b'\x01') time.sleep(0.5) open(DIGITAL_OUTPUT_0_CHANNEL_3 , "wb").write(b'\x00') time.sleep(0.5)
#include <stdio.h> #include <unistd.h> #define DIGITAL_OUTPUT_0_CHANNEL_3 "/tmp/cfnet-fs/digital-output/0/channel/3/state.txt" static void write_text(const char *path, const char *str) { FILE *f = fopen(path, "w"); fputs(str, f); fclose(f); } int main(void) { while (1) { write_text(DIGITAL_OUTPUT_0_CHANNEL_3 , "1"); usleep(500000); write_text(DIGITAL_OUTPUT_0_CHANNEL_3 , "0"); usleep(500000); } }
#include <stdio.h> #include <unistd.h> #define DIGITAL_OUTPUT_0_CHANNEL_3 "/tmp/cfnet-fs/digital-output/0/channel/3/state.bin" static void write_byte(const char *path, unsigned char value) { FILE *f = fopen(path, "wb"); fwrite(&value, 1, 1, f); fclose(f); } int main(void) { while (1) { write_byte(DIGITAL_OUTPUT_0_CHANNEL_3 , 1); // or 255, any non-zero value usleep(500000); write_byte(DIGITAL_OUTPUT_0_CHANNEL_3 , 0); usleep(500000); } }