User Tools

Site Tools


cfnet-fs:analog_output:index

cfnet-fs Analog Output Module

Each analog output module is represented under the cfnet-fs mount point by a directory at {mount-point}/analog-output/{module_address}/

$ tree -L 2 /tmp/cfnet-fs/analog-output/
/tmp/cfnet-fs/analog-output/
├── 0
│   └── channel
├── 1
│   └── channel
...

`channel` Subdirectory

Each analog output channel is represented under the cfnet-fs mount point by a directory at {mount-point}/analog-output/{module_address}/channel/{channel_address}/

$ tree /tmp/cfnet-fs/analog-output/0
/tmp/cfnet-fs/analog-output/0
└── channel
    ├── 0
    │   ├── raw.bin
    │   ├── raw.txt
    │   ├── volts.bin
    │   └── volts.txt
    └── 1
        ├── raw.bin
        ├── raw.txt
        ├── volts.bin
        └── volts.txt

Channel Files

Each analog output channel has 4 files:

  • raw.txt: The analog output channel's raw digital value as an ASCII string between 0 and 4095.
  • raw.bin: The analog output channel's raw digital value as an unsigned 16-bit integer between 0 and 4095. between 0 and 4095.
  • volts.txt: The analog output channel's voltage as an ASCII string between 0.0000 and 10.0000.
  • volts.bin: The analog output channel's voltage as 32-bit floating point value between 0.0 and 10.0.

Writing to any of these files will change the voltage of the analog 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.

Example: Set analog output module 0 channel 1's voltage

Shell Script

$ echo 5.0000 > /tmp/cfnet-fs/analog-output/0/channel/1/volts.txt

C#

const string ANALOG_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/analog-output/0/channel/1/volts.txt";
File.WriteAllText(ANALOG_OUTPUT_0_CHANNEL_3 , "5.0000");
const string ANALOG_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/analog-output/0/channel/1/volts.bin";
File.WriteAllBytes(ANALOG_OUTPUT_0_CHANNEL_3, BitConverter.GetBytes(5.0f));

Python

ANALOG_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/analog-output/0/channel/1/volts.txt"
 
with open(ANALOG_OUTPUT_0_CHANNEL_3, "w") as f:
    f.write("5.0000")
import struct
 
ANALOG_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/analog-output/0/channel/1/volts.bin"
 
value = 5.0
with open(ANALOG_OUTPUT_0_CHANNEL_3, "wb") as f:
    f.write(struct.pack("<f", value))

C

#include <stdio.h>
 
const char* ANALOG_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/analog-output/0/channel/1/volts.txt";
 
int main(void)
{
    FILE *f = fopen(ANALOG_OUTPUT_0_CHANNEL_3, "w");
    fputs("5.0000", f);
    fclose(f);
 
    return 0;
}
#include <stdio.h>
 
const char* ANALOG_OUTPUT_0_CHANNEL_3 = "/tmp/cfnet-fs/analog-output/0/channel/1/volts.bin";
 
int main(void)
{
    float value = 5.0f;
 
    FILE *f = fopen(ANALOG_OUTPUT_0_CHANNEL_3, "wb");
    fwrite(&value, sizeof(float), 1, f);
    fclose(f);
 
    return 0;
}
cfnet-fs/analog_output/index.txt · Last modified: by 127.0.0.1