0
Zaber 장치를 둘 이상의 직렬 포트에 연결하고 단일 스크립트에서 모든 것을 제어 할 수 있습니까? 스크립트는 Zaber Console에서 실행 중이며 어느 포트에서나 장치간에 동작을 조정할 수 있어야합니다.여러 직렬 포트에 Zaber 장치 스크립팅
Zaber 장치를 둘 이상의 직렬 포트에 연결하고 단일 스크립트에서 모든 것을 제어 할 수 있습니까? 스크립트는 Zaber Console에서 실행 중이며 어느 포트에서나 장치간에 동작을 조정할 수 있어야합니다.여러 직렬 포트에 Zaber 장치 스크립팅
예, 스크립트에서 더 많은 직렬 포트를 열 수 있습니다. Zaber Console 프로그램이 일반적으로 수행하는 모든 구성을 복제하면됩니다. 직렬 포트가 열리면 대화 개체를 정상적으로 사용할 수 있습니다. 두 개의 장치 사이의 이동을 조정하려면 대화 주제 항목을 사용하여 응답을 기다립니다. 자세한 내용은 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;
}