Difference between revisions of "2600"
(+system overview & design assistant) |
m (→Matlab) |
||
(23 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
===Design Assistant=== | ===Design Assistant=== | ||
− | To help you quickly determine exactly what you need for your application, please visit Sensoray's automated | + | To help you quickly determine exactly what you need for your application, including a wiring diagram and bill of materials, please visit Sensoray's fully automated Design Assistant. |
− | [http://www.sensoray.com/bombuild/2600bom.htm Design Assistant] | + | |
+ | [[File:Design assistant.gif|link=|alt=]] [http://www.sensoray.com/bombuild/2600bom.htm Design Assistant] | ||
==2601== | ==2601== | ||
Line 35: | Line 36: | ||
====Configuration program==== | ====Configuration program==== | ||
− | A | + | A Windows-compatible configuration program, cfg2601.exe, is used to set the 2601's static IP address. You will also need a serial crossover cable, which may be connected to any COM port on the computer. The other end of this cable must be connected to COM4 on the 2601 module. |
− | The program | + | The program requires a command line argument which indicates the COM port on your computer you are using. |
− | + | The program can be invoked in several ways. For example, when connecting to COM1 on your computer, you can invoke the program as follows: | |
− | + | ||
− | + | ||
− | + | * Create a shortcut to cfg2601.exe. To do this, right-click on cfg2601.exe (in Windows Explorer) and, while holding down the right mouse button, drag onto your desktop and select "Create shortcuts here". | |
+ | * Right-click on the new shortcut and select "Properties" | ||
+ | * Change the Target to specify the COM port you are using. In this case, change <code>cfg2601.exe</code> to <code>cfg2601.exe 1</code> and then click OK. | ||
+ | * Double-click on the shortcut to run the program | ||
− | + | Alternatively, you can run the program from a shell console. For example, if you are using the computer's COM1 port: | |
− | + | ||
− | Or | + | * Open a console window and switch to the directory that contains cfg2601.exe |
+ | * Type <code>cfg2601 1</code> at the command prompt and hit Enter | ||
+ | |||
+ | Or you can do this: | ||
* Click Start|Run | * Click Start|Run | ||
− | * Enter the exe path followed by | + | * Enter the exe path followed by <code>cfg2601 1</code>, then click OK |
===Automatic reset=== | ===Automatic reset=== | ||
Line 80: | Line 84: | ||
===Slow link detection=== | ===Slow link detection=== | ||
− | As | + | As discussed above, by default, the 2601 will automatically reset every ten seconds when it is not communicating. When this happens, the interface (computer or network switch) to which the 2601 is connected will momentarily lose its Ethernet link; this can be seen when the interface's link indicator briefly turns off. |
− | To solve this problem, you | + | Upon reset, the 2601 will quickly boot and become ready to communicate. However, some interfaces are slow to detect this and establish a link. While the link is down, the client is unable to communicate with the 2601. In some cases, the link process may be so slow that it becomes impossible to to communicate with the 2601. To solve this problem, you must take measures to speed up the link process. There are two ways to do this: |
+ | * Insert a "fast" network switch (one that quickly establishes a link) between the 2601 and the client's slow interface. This ensures that the client link will never go down, and that a link will be quickly established upon 2601 reset. | ||
+ | * Configure the client's interface for fixed 100MBps/half duplex operation. This speeds up linking by making link negotiation unnecessary. | ||
===Windows XP tweaks=== | ===Windows XP tweaks=== | ||
Line 222: | Line 228: | ||
==System== | ==System== | ||
+ | |||
+ | ===Terminal block connections=== | ||
+ | |||
+ | Some modules (e.g., 2601, 2608) provide terminal blocks for connecting to field wiring. For general information about these, see [[Terminal block connections, recommended practice]]. | ||
===Troubleshooting disruptive interference=== | ===Troubleshooting disruptive interference=== | ||
Line 236: | Line 246: | ||
# One at a time, connect field cables to the IOM. As each field wire is connected, determine whether the problem appears and, if so, proceed to the next step. | # One at a time, connect field cables to the IOM. As each field wire is connected, determine whether the problem appears and, if so, proceed to the next step. | ||
# View the field cable signal with an oscilloscope to determine why it is causing interference. | # View the field cable signal with an oscilloscope to determine why it is causing interference. | ||
+ | |||
+ | ==Matlab== | ||
+ | |||
+ | The following example shows how to use the 2600 DLL in Matlab to read counter values from an attached 2620 encoder. | ||
+ | |||
+ | % // Sensoray 2600 matlab example | ||
+ | % // This example assumes a 2620 is connected on port 0 | ||
+ | % // load the 2600 library/dll | ||
+ | % // make sure correct dll is in Matlab path (32-bit for 32-bit Matlab, | ||
+ | % // 64-bit for 64-bit Matlab) | ||
+ | % // Displays count from attached 2620 encoder module | ||
+ | loadlibrary('s2600.dll', 'app2600.h', 'addheader','s26app.h', ... | ||
+ | 'alias','S2600Lib'); | ||
+ | |||
+ | % // display the current DLL version | ||
+ | [version_str] = calllib('S2600Lib', 'S26_DriverVersion'); | ||
+ | |||
+ | % open the dll | ||
+ | rc = calllib('S2600Lib', 'S26_DLLOpen', 1); | ||
+ | |||
+ | % //set up io module status info pointer. | ||
+ | % // Iom status info. declare allocated pointer space for DLL | ||
+ | iom_status_ptr = libpointer('uint8Ptr',zeros(16,1,'uint8')); | ||
+ | disp("S2600 libraries loaded. Version: " + version_str); | ||
+ | |||
+ | % // Open the MM at the default IP address | ||
+ | % // In this example, only one MM is present in the system | ||
+ | % // so zero-indiced mmhandle is 0. | ||
+ | |||
+ | mmhandle = 0; | ||
+ | ipaddr = '10.10.10.1'; | ||
+ | rc = calllib('S2600Lib','S26_BoardOpen', mmhandle, '0', ipaddr); | ||
+ | % // retry connection if call failed | ||
+ | while rc ~= 0 | ||
+ | rc = calllib('S2600Lib','S26_BoardOpen', mmhandle, '0', ipaddr); | ||
+ | pause(0.25); | ||
+ | disp("Attempting to establish a connection with the MM."); | ||
+ | end | ||
+ | |||
+ | disp("MM was successfully opened."); | ||
+ | % // Reset the I/O system. | ||
+ | rc = calllib('S2600Lib','S26_ResetNetwork', mmhandle); | ||
+ | |||
+ | while rc == 0 | ||
+ | rc = calllib('S2600Lib','S26_ResetNetwork', mmhandle); | ||
+ | pause(0.25); | ||
+ | end | ||
+ | |||
+ | disp("MM was successfully reset."); | ||
+ | |||
+ | % // Disable automatic reset (watchdog) if desired | ||
+ | sched_ptr = calllib('S2600Lib','S26_SchedOpen',0,1); | ||
+ | rc = calllib('S2600Lib','S26_Sched2601_SetWatchdog',sched_ptr,0); % Disable watchdog | ||
+ | % // call schedexecute to complete transaction(s) | ||
+ | [rc, out_void_ptr, out_ptr] = calllib('S2600Lib','S26_SchedExecute',sched_ptr, 1000, iom_status_ptr); | ||
+ | |||
+ | if rc ~= 0 | ||
+ | disp("Watchdog disable failed."); | ||
+ | else | ||
+ | disp("Watchdog was successfully disabled."); | ||
+ | end | ||
+ | |||
+ | % //Detect and register all i/o modules connected to the 2601 main module. | ||
+ | |||
+ | msec_gateway = 100; % //timeout/retry for gateway (ms) | ||
+ | msec_comport = 100; % //timeout/retry for comport transactions (ms) | ||
+ | com_retries = 20; % // number of comport retries. | ||
+ | gateway_retries = 20; % // number of gateway retries. | ||
+ | |||
+ | nboards_ptr = libpointer('uint16Ptr',0); % Number of detected iom's. | ||
+ | iomtype_ptr = libpointer('uint16Ptr',zeros(16,1,'uint16')); % Detected iom types. | ||
+ | |||
+ | [rcs, num_ioms_ptr, ioms_out_ptr, status_out_ptr] = calllib('S2600Lib','S26_RegisterAllIoms', mmhandle, msec_gateway, nboards_ptr, iomtype_ptr, iom_status_ptr, gateway_retries); | ||
+ | |||
+ | % // Set encoder mode settings | ||
+ | % // In this example, channels are set to quadrature encoding | ||
+ | clockMode = 3; %// 3 = quadrature x4, clock on all A and B edges. | ||
+ | % // Index pin polarity | ||
+ | indexPolarity = 0; % Index pin polarity: 1 = active low, 0 = active high. | ||
+ | |||
+ | for IOM = 0 : (num_ioms_ptr-1) | ||
+ | sched_ptr = calllib('S2600Lib','S26_SchedOpen',0,1); | ||
+ | pause(1); | ||
+ | [rc, void_ptr] = calllib('S2600Lib','S26_Sched2620_SetModeEncoder',sched_ptr,IOM,0,indexPolarity,0,clockMode); | ||
+ | pause(1); | ||
+ | [rc, out_void_ptr, out_ptr] = calllib('S2600Lib','S26_SchedExecute',sched_ptr, 1000, iom_status_ptr); | ||
+ | disp(rc); | ||
+ | pause(1); | ||
+ | end | ||
+ | |||
+ | % // Read Encoders | ||
+ | % // Latch | ||
+ | CTC_TRIG_PRELOAD = 1; | ||
+ | CTC_TRIG_LATCH = 2; | ||
+ | |||
+ | counts_ptr = libpointer('uint32Ptr',0); % Counts. | ||
+ | timestamp_ptr = libpointer('uint16Ptr',0); % Timestamps. | ||
+ | |||
+ | % Sets control register for IOM at port 0. Add other IOMs as necessary | ||
+ | sched_ptr = calllib('S2600Lib','S26_SchedOpen',0,1); | ||
+ | [rc, void_ptr] = calllib('S2600Lib','S26_Sched2620_SetControlReg',sched_ptr,0,0,CTC_TRIG_LATCH); | ||
+ | pause(1); | ||
+ | [rc, out_void_ptr, out_ptr] = calllib('S2600Lib','S26_SchedExecute',sched_ptr, 1000, iom_status_ptr); | ||
+ | pause(1); | ||
+ | disp(rc); | ||
+ | |||
+ | quad_inputs = 4; % // Available channels on 2620 modules | ||
+ | % // allocate the count list in advance | ||
+ | count_list = zeros(num_ioms_ptr,quad_inputs); | ||
+ | disp("CountList before measurement:"); | ||
+ | disp(count_list); | ||
+ | |||
+ | % // This loop assumes the 2620s are connected starting at the first port (0) and | ||
+ | % // connected sequentially without gaps. | ||
+ | % // A more comprehensive solution would look at ioms_out_ptr (array of attached IOM types) | ||
+ | % // and determine which ports have 2620s attached. | ||
+ | for iom = 0 : (num_ioms_ptr-1) | ||
+ | % // Fetch counter values of attached 2620s | ||
+ | for chan = 0:(quad_inputs-1) | ||
+ | sched_ptr = calllib('S2600Lib','S26_SchedOpen',0,1); | ||
+ | [rc, void_ptr, counts, TimeStamp] = calllib('S2600Lib','S26_Sched2620_GetCounts',sched_ptr,iom,chan,counts_ptr,timestamp_ptr); | ||
+ | pause(1); | ||
+ | [rc, out_void_ptr, out_ptr] = calllib('S2600Lib','S26_SchedExecute',sched_ptr, 1000, iom_status_ptr); | ||
+ | count_list(iom+1,chan+1) = counts; | ||
+ | disp(counts); | ||
+ | end | ||
+ | end | ||
+ | |||
+ | disp(" "); | ||
+ | disp("Counts:"); | ||
+ | disp(" "); | ||
+ | disp(count_list); | ||
+ | |||
+ | % // Clean up and close the DLL | ||
+ | % // Note: Do not use S26_BoardClose, it will be called internally | ||
+ | % // in S26_DLLClose | ||
+ | % //Warning. S26_DLLClose will hang if S26_SchedExecute is not called after | ||
+ | % //initializing a transaction (with SchedOpen, GetCounts, etc...) | ||
+ | % //Make sure all SchedOpen calls are completed. | ||
+ | |||
+ | calllib('S2600Lib','S26_DLLClose') | ||
+ | unloadlibrary S2600Lib |
Latest revision as of 16:14, 1 December 2023
Sensoray's 2600 series is a low-cost, modular Ethernet-based measurement and control system designed for applications such as machine control, industrial process control, building automation and remote data acquisition.
Contents |
[edit] System overview
A basic system consists of a 2601 module and one or more I/O modules, a 24 VDC power source, and interconnecting cables.
[edit] Design Assistant
To help you quickly determine exactly what you need for your application, including a wiring diagram and bill of materials, please visit Sensoray's fully automated Design Assistant.
[edit] 2601
Model 2601 is an Ethernet-based communication hub for the 2600 series of I/O modules. It supports up to 16 I/O modules and has 4 serial COM ports.
[edit] Is a 2601 module required?
Yes, a 2601 is always required because it provides the Ethernet interface for a system of up to 16 I/O modules (e.g., 2608, 2610, 2652, etc.). The I/O modules do not have an Ethernet interface; they rely on a 2601 for this function.
This requirement is not an issue in systems with a large number of I/O points, for which the 2600 series is an ideal, low cost solution. If you have a small number of I/O points and need to minimize the I/O system's footprint, consider these alternative solutions:
- Model 2410 — Ethernet 48-channel digital I/O
- Model 2426 — Ethernet multifunction analog/digital I/O w/serial COM
[edit] Setting the IP address
[edit] Null-modem cable
When configuring the 2601's IP address, a null-modem cable must always be used to connect the configuration computer to the 2601. If your computer has a built-in RS-232 serial port, connect one end of the null-modem cable to the computer and the other end to 2601 COM4.
If your computer doesn't have a serial port then you can use a USB-to-serial adapter. To do this, connect one end of the null-modem cable to the adapter's serial connector and the other end to 2601 COM4.
[edit] Configuration program
A Windows-compatible configuration program, cfg2601.exe, is used to set the 2601's static IP address. You will also need a serial crossover cable, which may be connected to any COM port on the computer. The other end of this cable must be connected to COM4 on the 2601 module.
The program requires a command line argument which indicates the COM port on your computer you are using.
The program can be invoked in several ways. For example, when connecting to COM1 on your computer, you can invoke the program as follows:
- Create a shortcut to cfg2601.exe. To do this, right-click on cfg2601.exe (in Windows Explorer) and, while holding down the right mouse button, drag onto your desktop and select "Create shortcuts here".
- Right-click on the new shortcut and select "Properties"
- Change the Target to specify the COM port you are using. In this case, change
cfg2601.exe
tocfg2601.exe 1
and then click OK. - Double-click on the shortcut to run the program
Alternatively, you can run the program from a shell console. For example, if you are using the computer's COM1 port:
- Open a console window and switch to the directory that contains cfg2601.exe
- Type
cfg2601 1
at the command prompt and hit Enter
Or you can do this:
- Click Start|Run
- Enter the exe path followed by
cfg2601 1
, then click OK
[edit] Automatic reset
- My 2601 resets every 10 seconds (approximately) — is this normal?
This is normal behavior when no Ethernet clients are communicating with the 2601.
The 2601 employs a communication watchdog timer to measure the time since it last communicated with a client. By default, the watchdog will reset the 2601 if no communication has occurred within the last ten seconds, which in turn will reset all IOMs (slave modules) connected to the 2601. This behavior ensures that all I/O will be turned off in the event the client shuts down abnormally.
The watchdog interval defaults to ten seconds upon 2601 power-up or reset. If a different interval is needed, use a function like this to reprogram it:
u32 SetWatchdogInterval(u32 hbd, u8 tmax) { void *x = S26_SchedOpen(hbd, 1); S26_Sched2601_SetWatchdog(x, tmax); // timeout in 0.1s units return S26_SchedExecute(x, 1000, 0); }
For example, this will set the watchdog interval to 3.5 seconds:
SetWatchdogInterval(0, 35); // 35 * 0.1s = 3.5 seconds
To completely disable the watchdog (so it cannot reset the 2601), set the interval to zero as shown below. Note that if the 2601 is reset for any reason (e.g., via command or power cycling), the interval will revert to ten seconds and must be disabled again.
SetWatchdogInterval(0, 0); // 0 = disable watchdog
[edit] Slow link detection
As discussed above, by default, the 2601 will automatically reset every ten seconds when it is not communicating. When this happens, the interface (computer or network switch) to which the 2601 is connected will momentarily lose its Ethernet link; this can be seen when the interface's link indicator briefly turns off.
Upon reset, the 2601 will quickly boot and become ready to communicate. However, some interfaces are slow to detect this and establish a link. While the link is down, the client is unable to communicate with the 2601. In some cases, the link process may be so slow that it becomes impossible to to communicate with the 2601. To solve this problem, you must take measures to speed up the link process. There are two ways to do this:
- Insert a "fast" network switch (one that quickly establishes a link) between the 2601 and the client's slow interface. This ensures that the client link will never go down, and that a link will be quickly established upon 2601 reset.
- Configure the client's interface for fixed 100MBps/half duplex operation. This speeds up linking by making link negotiation unnecessary.
[edit] Windows XP tweaks
[edit] Speed up link detection
- I have a direct connection between my computer and the 2600 via an Ethernet crossover cable. I see the 2600's link LED turn on shortly after it resets, but when it does, there is a long delay before my computer indicates a valid connection. Is there a way to speed this up?
Open the Network Connections dialog and right-click on the 2600's network connection. Click on the Configure button, then select the Advanced tab. Select the "Link Speed & Duplex" property, then go to the Value pulldown and select "100Mbps/Half Duplex."
[edit] Eliminate annoying balloon tips
- When my application is not running, irritating balloon tips keep popping up to report the 2600's cyclic disconnected/reconnected network connection. How can I prevent this from happening?
Run regedit.exe and create (if it doesn't already exist) or edit (if it already exists) the following key:
HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Explorer/Advanced
Set the key as follows:
EnableBalloonTips REG_DWORD 0
Restart or logoff/logon to apply the changes.
[edit] Eliminate "red x" status notification
- When my application is not running, I sometimes see an irritating "red x" network status icon in the notification area. How can I prevent this?
- I unchecked the "Show icon in notification area when connected" box in the connection properties dialog, but this hides the icon only when the connection is active. The RedX icon keeps appearing briefly, then disappearing.
- I checked the "Hide inactive icons" in the Taskbar properties and set the network connection icon to "Always hide" in the Customize Notifications dialog, but it doesn't seem to stick.
This solution will completely eliminate the connection status icon.
Run regedit.exe and delete this key:
HKEY_CLASSES_ROOT\CLSID\{7007ACCF-3202-11D1-AAD2-00805FC1270E}
Restart or logoff/logon to apply the change.
[edit] 2608
Model 2608 is an analog I/O module that connects to Ethernet through a 2601 communication module. It has sixteen differential analog inputs and 0, 4 or 8 analog outputs. It is a member of the 2600 series of smart I/O modules.
[edit] Common mode voltage range
The CMV range for analog inputs is -10 to +10V for both the 100mV and 10V input ranges.
[edit] Visual identification
- Is there a visible difference between models 2608-0, -4 and -8?
Yes. The 2608 circuit board has footprints for two DAC chips (marked "LTC2704") which are located near the analog output connectors. On earlier board revisions, these chips have reference designators U6 and U27; on newer revisions they are U9 and U29. The DAC chips are populated differently for each model. You can identify the model by the number of installed DAC chips:
Model | DAC chips |
---|---|
2608-0 | 0 |
2608-4 | 1 |
2608-8 | 2 |
[edit] 4-20 mA sensors
- How do I connect 4-20 mA sensors and power them from the 2608 (vs. from external power supply)?
For each 4-20 mA sensor, you must install two shunts on the associated IPB:
- Pin 3-4, to supply +24V power to the sensor.
- Pin 9-10, to insert a 500 ohm resistor into the current loop.
Three wires are needed for each sensor. Two wires are used to connect the sensor to the 2608 terminal block (TB); the third wire connects two TB pins together:
- Sensor+ to Pwr
- Sensor- to Ain+
- Ain- to Com
For example, on odd-numbered channels connect
- Sensor+ to TB.1
- Sensor- to TB.3
- TB.4 to TB.5
On even-numbered channels connect
- Sensor+ to TB.6
- Sensor- to TB.8
- TB.9 to TB.10
[edit] 2610
Model 2610 is a modular, 48 channel digital I/O interface that connects to Ethernet through a 2601 communication module. It has 48 general-purpose digital I/O channels that can independently serve as inputs, outputs, or in wired-OR mode.
[edit] Input voltage thresholds
Parameter | Value |
---|---|
VIL, MAX | 0.8 V |
VIH, MIN | 3.5 V |
[edit] 2652/2653
Models 2652 and 2653 are DIN rail mountable modules that allow solid state relays (SSRs) to be monitored and controlled over Ethernet. Sockets are provided for eight (model 2652) or sixteen (model 2653) SSRs. Each socket may be populated with any supported SSR type, including AC in, AC out, DC in and DC out, or left unpopulated. The modules, which work in conjunction with a model 2601 communication module, are members of the 2600 series of smart I/O modules.
[edit] Crimp pins and mating connectors
We recommend the following parts from TE Connectivity:
- Crimp pins: PN 770988-1
- Mating connectors: PN 172166-1
- Crimp tool: PN 91522-1.
[edit] Compatible SSRs
Models 2652/2653 accept standard-format, 24V SSRs from Crydom and other vendors. For example, these Grayhill SSRs are compatible:
- 70-OAC24 - 120V AC output
- 70-OAC24A - 240V AC output
- 70-ODC24 - 60V DC output
- 70-IAC24 - 120V AC input
- 70-IAC24A - 240V AC input
- 70-IDC24 - 32V DC input
[edit] Output response time
- What is the response time from command to SSR state change?
The maximum response time is the sum of the transaction time, FSM clock period and SSR turn on/off time:
- Command transaction time. This is the time it takes to send a command to the module and receive a reply. Typically, it is approximately 700 microseconds on a dedicated LAN, but may be longer if the LAN has high network traffic, or transactions are conveyed through multiple switches/routers, or the CPU is heavily loaded.
- FSM clock period. Models 2652/2653 employ a finite state machine which synchronously updates SSR states at 500 Hz. Consequently, the 2652/2653 will change the SSR control signals within 0-2 milliseconds of receiving a command.
- SSR turn on/off times. An SSR doesn't turn on or off instantly in response to a control change; typical SSR response times range from 50 microseconds to 10 milliseconds.
[edit] System
[edit] Terminal block connections
Some modules (e.g., 2601, 2608) provide terminal blocks for connecting to field wiring. For general information about these, see Terminal block connections, recommended practice.
[edit] Troubleshooting disruptive interference
Electro-mechanical equipment may generate EMI which, if not properly suppressed, can interfere with normal operation of the 2600 system. This manifests in various ways, including analog measurement noise, momentary communication disruptions, and in extreme cases, watchdog resets of the 2601 module.
If your 2600 system is experiencing EMI-induced disruptions, first try to determine where the EMI is entering the system. To do this, gradually add components to the I/O system until the problem appears:
- Disconnect all cables from the 2601.
- Connect power to the 2601. The 2601 should perform a self-induced reset approximately every ten seconds. At this point, if your equipment causes unexpected 2601 resets then you may need to power the 2600 system from an isolated 24 VDC power supply.
- Connect Ethernet to the 2601 and run Sensoray's 2600 demo program. Make sure that only the demo program is communicating with the 2601 (your own application software should not be running). If your equipment causes unexpected 2601 resets or communication faults then you may need to use a shielded Ethernet cable.
- One at a time, connect the IOMs (e.g., 2608, 2610, 2652) to the 2601. As each module is connected, determine whether the problem appears and, if so, proceed to the next step.
- Disconnect all field wiring from the IOM so that the IOM is only connected to the 2601 via a Cat-5 cable and, in some cases, an additional, separate power cable.
- One at a time, connect field cables to the IOM. As each field wire is connected, determine whether the problem appears and, if so, proceed to the next step.
- View the field cable signal with an oscilloscope to determine why it is causing interference.
[edit] Matlab
The following example shows how to use the 2600 DLL in Matlab to read counter values from an attached 2620 encoder.
% // Sensoray 2600 matlab example % // This example assumes a 2620 is connected on port 0 % // load the 2600 library/dll % // make sure correct dll is in Matlab path (32-bit for 32-bit Matlab, % // 64-bit for 64-bit Matlab) % // Displays count from attached 2620 encoder module loadlibrary('s2600.dll', 'app2600.h', 'addheader','s26app.h', ... 'alias','S2600Lib'); % // display the current DLL version [version_str] = calllib('S2600Lib', 'S26_DriverVersion'); % open the dll rc = calllib('S2600Lib', 'S26_DLLOpen', 1); % //set up io module status info pointer. % // Iom status info. declare allocated pointer space for DLL iom_status_ptr = libpointer('uint8Ptr',zeros(16,1,'uint8')); disp("S2600 libraries loaded. Version: " + version_str); % // Open the MM at the default IP address % // In this example, only one MM is present in the system % // so zero-indiced mmhandle is 0. mmhandle = 0; ipaddr = '10.10.10.1'; rc = calllib('S2600Lib','S26_BoardOpen', mmhandle, '0', ipaddr); % // retry connection if call failed while rc ~= 0 rc = calllib('S2600Lib','S26_BoardOpen', mmhandle, '0', ipaddr); pause(0.25); disp("Attempting to establish a connection with the MM."); end disp("MM was successfully opened."); % // Reset the I/O system. rc = calllib('S2600Lib','S26_ResetNetwork', mmhandle); while rc == 0 rc = calllib('S2600Lib','S26_ResetNetwork', mmhandle); pause(0.25); end disp("MM was successfully reset."); % // Disable automatic reset (watchdog) if desired sched_ptr = calllib('S2600Lib','S26_SchedOpen',0,1); rc = calllib('S2600Lib','S26_Sched2601_SetWatchdog',sched_ptr,0); % Disable watchdog % // call schedexecute to complete transaction(s) [rc, out_void_ptr, out_ptr] = calllib('S2600Lib','S26_SchedExecute',sched_ptr, 1000, iom_status_ptr); if rc ~= 0 disp("Watchdog disable failed."); else disp("Watchdog was successfully disabled."); end % //Detect and register all i/o modules connected to the 2601 main module. msec_gateway = 100; % //timeout/retry for gateway (ms) msec_comport = 100; % //timeout/retry for comport transactions (ms) com_retries = 20; % // number of comport retries. gateway_retries = 20; % // number of gateway retries. nboards_ptr = libpointer('uint16Ptr',0); % Number of detected iom's. iomtype_ptr = libpointer('uint16Ptr',zeros(16,1,'uint16')); % Detected iom types. [rcs, num_ioms_ptr, ioms_out_ptr, status_out_ptr] = calllib('S2600Lib','S26_RegisterAllIoms', mmhandle, msec_gateway, nboards_ptr, iomtype_ptr, iom_status_ptr, gateway_retries); % // Set encoder mode settings % // In this example, channels are set to quadrature encoding clockMode = 3; %// 3 = quadrature x4, clock on all A and B edges. % // Index pin polarity indexPolarity = 0; % Index pin polarity: 1 = active low, 0 = active high. for IOM = 0 : (num_ioms_ptr-1) sched_ptr = calllib('S2600Lib','S26_SchedOpen',0,1); pause(1); [rc, void_ptr] = calllib('S2600Lib','S26_Sched2620_SetModeEncoder',sched_ptr,IOM,0,indexPolarity,0,clockMode); pause(1); [rc, out_void_ptr, out_ptr] = calllib('S2600Lib','S26_SchedExecute',sched_ptr, 1000, iom_status_ptr); disp(rc); pause(1); end % // Read Encoders % // Latch CTC_TRIG_PRELOAD = 1; CTC_TRIG_LATCH = 2; counts_ptr = libpointer('uint32Ptr',0); % Counts. timestamp_ptr = libpointer('uint16Ptr',0); % Timestamps. % Sets control register for IOM at port 0. Add other IOMs as necessary sched_ptr = calllib('S2600Lib','S26_SchedOpen',0,1); [rc, void_ptr] = calllib('S2600Lib','S26_Sched2620_SetControlReg',sched_ptr,0,0,CTC_TRIG_LATCH); pause(1); [rc, out_void_ptr, out_ptr] = calllib('S2600Lib','S26_SchedExecute',sched_ptr, 1000, iom_status_ptr); pause(1); disp(rc); quad_inputs = 4; % // Available channels on 2620 modules % // allocate the count list in advance count_list = zeros(num_ioms_ptr,quad_inputs); disp("CountList before measurement:"); disp(count_list); % // This loop assumes the 2620s are connected starting at the first port (0) and % // connected sequentially without gaps. % // A more comprehensive solution would look at ioms_out_ptr (array of attached IOM types) % // and determine which ports have 2620s attached. for iom = 0 : (num_ioms_ptr-1) % // Fetch counter values of attached 2620s for chan = 0:(quad_inputs-1) sched_ptr = calllib('S2600Lib','S26_SchedOpen',0,1); [rc, void_ptr, counts, TimeStamp] = calllib('S2600Lib','S26_Sched2620_GetCounts',sched_ptr,iom,chan,counts_ptr,timestamp_ptr); pause(1); [rc, out_void_ptr, out_ptr] = calllib('S2600Lib','S26_SchedExecute',sched_ptr, 1000, iom_status_ptr); count_list(iom+1,chan+1) = counts; disp(counts); end end disp(" "); disp("Counts:"); disp(" "); disp(count_list); % // Clean up and close the DLL % // Note: Do not use S26_BoardClose, it will be called internally % // in S26_DLLClose % //Warning. S26_DLLClose will hang if S26_SchedExecute is not called after % //initializing a transaction (with SchedOpen, GetCounts, etc...) % //Make sure all SchedOpen calls are completed. calllib('S2600Lib','S26_DLLClose') unloadlibrary S2600Lib