I am attempting to use a jrk 21v3 to control a solenoid. Everything works fine in the Configuration Utility with the following parameters:
Input mode: Serial
Serial Interface: USB Dual Port
Feedback mode: (None)
To engage the solenoid, I set the target in the “Manually set target” panel to 4095 (or 0). To disengage, I simply stop the motor.
I am having trouble replicating this behavior in C code however. I am running a linear actuator with a second jrk with no problems. I set the target using the compact protocol, and the linear actuator behaves appropriately.
With the solenoid, when I set the target, nothing moves. I have tried both setting the target in high and low resolution to no avail. Here is the code I am using to attempt to drive the solenoid:
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#ifdef _WIN32
#define O_NOCTTY 0
#else
#include <termios.h>
#endif
int jrkSetTarget(int fd)
{
unsigned short target = 0xA58;
unsigned char command[] = {0xE1, target};
if (write(fd, command, sizeof(command)) == -1)
{
perror("error writing");
return -1;
}
return 0;
}
int main()
{
const char * device = "/dev/cu.usbmodem00195891"; // Mac OS X
int fd = open(device, O_RDWR | O_NOCTTY);
if (fd == -1)
{
perror(device);
return 1;
}
#ifndef _WIN32
struct termios options;
tcgetattr(fd, &options);
options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
options.c_oflag &= ~(ONLCR | OCRNL);
tcsetattr(fd, TCSANOW, &options);
#endif
jrkSetTarget(fd);
return 0;
}