sending com port command
Paul Groot
pfc.groot at gmail.com
Tue Feb 21 22:20:26 UTC 2012
Hi Erin,
Ah, I described a solution for a 'legacy' ADR device because you
linked to the RS232 example. But if I understand this correctly, you
are using an ADU (USB only) device...
However, if the device you have supports legacy RS232 connections, you
should try the following first because RS232 it is a bit easier to use
than the USB interface DLL: First check which (virtual) COM port is
being assigned by windows after installing the driver. If the USB
device connects as virtual RS232, you should be able to find it under
control panel>device manager->COM and LPT ports. Windows often assigns
a port number >4, which might be problemematic with EPrime (not sure
if this is less critical in EPrime 2.) Just try to change the port
number to the first available value below 4. If the PC has 1 or 2
physical COM ports, you should skip those numbers. Also note that the
port number often changes when a different USB port is used.
If RS232 is *not* an option (i.e. no new COM port is added when you
plugin the USB cable), you should use the DLL interface to connect to
the USB channels. EBasic supports calling functions in external DLL's,
so that should be no problem. To do this, you should declare all DLL
functions first. For example, you can put the following declarations
in the global user script section:
Declare Function OpenAduDevice Lib "AduHid.DLL" (ByVal iTimeout As
Long) As Long
Declare Function WriteAduDevice Lib "AduHid.DLL" (ByVal aduHandle As
Long, ByVal lpBuffer As String, ByVal lNumberOfBytesToWrite As Long,
ByRef lBytesWritten As Long, ByVal iTimeout As Long) As Long
Declare Function ReadAduDevice Lib "AduHid.DLL" (ByVal aduHandle As
Long, ByVal lpBuffer As String, ByVal lNumberOfBytesToRead As Long,
ByRef lBytesRead As Long, ByVal iTimeout As Long) As Long
Declare Function CloseAduDevice Lib "AduHid.DLL" (ByVal iHandle As Long) As Long
(more info here http://www.ontrak.net/ADUSDK/MinimalCompile-VB.html)
When the declarations are defined, you should be able to call the
functions in inline script just as if the functions are part of
EBasic:
' you would probably put this declaration also in the global section
Dim aduHandle As Long
'then in some inline script:
aduHandle = OpenAduDevice(0)
The VisualBasic example contains further details on the WriteAduDevice
function. Also don't forget to close the channel properly by calling
CloseAduDevice(aduHandle) before the end of the experiment.
best,
paul
2012/2/21 Erin <erin.siebert at gmail.com>:
> Thanks for the info Paul. I was thinking something like that may
> work. In the past, I have successfully triggered a serial port pump
> (via a usb to 9-pin serial port converter) in E-Prime sending text
> commands using a serial.writestring inline. (I installed a driver for
> the computer to recognize the serial-usb converter as a serial com
> port.)
>
> However, the equipment I am currently working with is a usb to usb
> connection, and E-Prime does not recognize it as a serial port. When
> I run the experiment with a serial device added, I get an "unable to
> open port" error, even when I go through and try every com port. Is
> there a way to send this signal through a traditional USB connection?
> thanks!
>
> Erin
>
>
>
>
> On Feb 20, 3:47 pm, Paul Groot <pfc.gr... at gmail.com> wrote:
>> Hi Erin,
>>
>> Although, in theory, it would be possible to use the WritePort command
>> to send bytes to a classicalserial(non-USB) RS232 port, it is
>> definitely not the way to go. Instead you should use a SerialDevice
>> object to communicate with a COM port. The easiest way is to add such
>> aSerialdevice in the following dialog:
>> E-Studio>Menu>Edit>Experiment>Devices>AddSerial. The default setting
>> should be OK (9600bps, 8bit, no parity, 1 stopbit). When you add this
>> device, EPrime will add a global SerialDevice object variable to your
>> script. The name of this variable will be 'Serial' if there is only
>> oneserialdevice.
>>
>> The next thing you should do is to add a single line of inline script
>> to send the command:
>>
>> SerialDevice.WriteString "sk0" & ebCr
>>
>> The ebCr constant is a cariage return that is probably required by the device.
>>
>> I'm not sure if the external device also needs to be initialised first
>> (by sending "CPA00000000" for example), but that's up to you to find
>> out ;-)
>>
>> Hope this helps,
>> Paul
>>
>> 2012/2/18 Erin <erin.sieb... at gmail.com>:
>>
>> > I am trying to send a command to an external device via ausb
>> > connection. The external device is an ADU200USBRelay I/O Interface
>> > (http://www.ontrak.net/ADUcommands.htm). This is a control box which
>> > triggers an automatic feeder for our monkeys. Using the control box's
>> > test software, I can trigger the auto feeder by sending the control
>> > box the command "sk0." So, I know I need E-Prime to send the command
>> > "sk0" to the ADU200 control box via ausbCOM port.
>>
>> > I have read the E-Prime help, and it appears it is difficult to send a
>> > non binary message via a com port (the WritePort command). It is
>> > possible I may need to use something called a Declare Statement, which
>> > is done outside of E-Prime. However, I am hoping this is not
>> > necessary.
>>
>> > Reading the OnTrak help, it appear a Visual Basic code similar to
>> > MSComm1.Output = "sk0" would work (http://www.ontrak.net/visual.htm),
>> > however this does not appear to be an option in E-Prime.
>>
>> > Any pointers would be very appreciated. Thank you!
>>
>> > Erin
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups "E-Prime" group.
>> > To post to this group, send email to e-prime at googlegroups.com.
>> > To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
>> > For more options, visit this group athttp://groups.google.com/group/e-prime?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "E-Prime" group.
> To post to this group, send email to e-prime at googlegroups.com.
> To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.
More information about the Eprime
mailing list