I have been using PoKey's Visual C# example to manually control digital outputs.
The problem is that the latency is about
2ms per bit out!
Since I am controlling 2 stepper motors, I am using 8 digital outputs (each are 1 bit).
This means that sending each 8 bit output takes
16ms!
I need to be able to change all 8 bits in under 1ms if possible.
By latency I mean the time it takes to execute a "set output" command and then start the next command.
I am controlling each bit individually with the function
PoKeysDevice_DLL.SetOutput(byte pinID, bool outputState);Is there a faster function? What about a function that can set more than one pin at a time?
My entire C# solution is attached, ready to run in Visual C# if you want to help me out
Here is the example file I based my code on:
http://www.poscope.com/uploads/files/PoKeysExamples.zip<C#/Example2_BasicPinFunctions>
Here is my main function&file used to measure latency: (note that it takes me 9 seconds to run the while loop 500 times)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Example2_BasicPinFunctions
{
class Program
{
public enum pinFunctionsEnum
{
pinFunctionInactive = 0,
pinFunctionDigitalInput = 2,
pinFunctionDigitalOutput = 4,
pinFunctionAnalogInput = 8,
pinFunctionAnalogOutput = 16,
pinInvert = 128
}
static void Main(string[] args)
{
// Create PoKeys55 device object
PoKeysDevice_DLL.PoKeysDevice device = new PoKeysDevice_DLL.PoKeysDevice();
// Enumerate devices (this step must never be ommited!)
int iNumDevices = device.EnumerateDevices();
if (iNumDevices == 0)
{
Console.WriteLine("No PoKeys55 devices found!");
Console.WriteLine("\nPress any key to exit");
Console.ReadKey();
return;
}
// Connect to first PoKeys55 device
device.ConnectToDevice(0);
int i;
// Set pins as digital output
for (i = 2; i <= 9; i++)
{
device.SetPinData((byte)(i - 1), (byte)(pinFunctionsEnum.pinFunctionDigitalOutput));
}
Console.WriteLine("Pins 2-9 set as digital output");
bool flop = false;
int j = 0;
////////////////////////////////////////////////////////////////IMPORTANT PART OF THE CODE
while (true)
{
for (i = 2; i <= 9; i++)
{
device.SetOutput((byte)(i - 1), flop); //is there a faster function that this one?
}
flop = !flop; //flop alternates true, false, true, false,...
j++;
if (j%500==0) {
Console.WriteLine("500 more done"); //prints every time the output changes 500 times (9 seconds)
}
}
////////////////////////////////////////////////////////////////END IMPORTANT PART OF THE CODE
// Disconnect from device
device.DisconnectDevice();
Console.WriteLine("\nEnd.\nPress any key to exit");
Console.ReadKey();
}
}
}