0
是否可以將Zaber設備連接到多個串行端口並通過單個腳本控制它們?該腳本正在運行Zaber Console,並且應該能夠協調任一端口上的設備之間的運動。多個串行端口上的腳本Zaber設備
是否可以將Zaber設備連接到多個串行端口並通過單個腳本控制它們?該腳本正在運行Zaber Console,並且應該能夠協調任一端口上的設備之間的運動。多個串行端口上的腳本Zaber設備
是的,您可以在腳本中打開更多串行端口。您只需複製我們的Zaber控制檯程序通常爲您所做的所有配置。串行端口打開後,您可以正常使用會話對象。爲了協調兩個設備之間的移動,您使用對話主題對象來等待響應。有關更多詳細信息,請閱讀Zaber庫幫助文件。你可以在腳本編輯器的幫助菜單中找到它。
// Example C# script showing how to open a second serial port and coordinate
// moves between the two.
#template(methods)
public override void Run()
{
// First port is the one that Zaber Console has already opened.
var portFacade1 = PortFacade;
// Now, we're going to open COM2 in the script.
// The using block makes sure we don't leave it open.
using (var portFacade2 = CreatePortFacade())
{
portFacade2.Open("COM2");
// Start a conversation with a device on each port.
// Note that the device numbers can be the same because they're on
// separate ports.
var conversation1 = portFacade1.GetConversation(1);
var conversation2 = portFacade2.GetConversation(1);
while (! IsCanceled)
{
MoveBoth(conversation1, conversation2, 0);
MoveBoth(conversation1, conversation2, 10000);
}
}
}
private void MoveBoth(
Conversation conversation1,
Conversation conversation2,
int position)
{
// Start a topic to wait for the response
var topic = conversation1.StartTopic();
// Send the command using Device.Send() instead of Request()
// Note the topic.MessageId parameter to coordinate request and response
conversation1.Device.Send(
Command.MoveAbsolute,
position,
topic.MessageId);
// While c1 is moving, also request c2 to move. This one just uses
// Request() because we want to wait until it finishes.
conversation2.Request(Command.MoveAbsolute, position);
// We know c2 has finished moving, so now wait until c1 finishes.
topic.Wait();
topic.Validate();
}
private ZaberPortFacade CreatePortFacade()
{
var packetConverter = new PacketConverter();
packetConverter.MillisecondsTimeout = 50;
var defaultDeviceType = new DeviceType();
defaultDeviceType.Commands = new List<CommandInfo>();
var portFacade = new ZaberPortFacade();
portFacade.DefaultDeviceType = defaultDeviceType;
portFacade.QueryTimeout = 1000;
portFacade.Port = new TSeriesPort(
new System.IO.Ports.SerialPort(),
packetConverter);
portFacade.DeviceTypes = new List<DeviceType>();
return portFacade;
}