ModbusRTU.cs 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414
  1. // ***********************************************************************
  2. // Module : ModbusRTUHelper for C#
  3. // Author : Lei Youbing
  4. // Created : 12-27-2017
  5. //
  6. // Last Modified By : Lei Youbing
  7. // Last Modified On : 2020-08-18
  8. // ***********************************************************************
  9. // Copyright (c) Shanghai AMP & MOONS' Automation Co., Ltd.. All rights reserved.
  10. // ***********************************************************************
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Runtime.InteropServices;
  14. namespace SHJX.Service.ServerClient.Modbus
  15. {
  16. public delegate void CSCallback();
  17. public struct StructRegisterValue
  18. {
  19. public int Count;
  20. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2048)]
  21. public int[] Values;
  22. };
  23. public struct StructCommand
  24. {
  25. public int Count;
  26. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4096)]
  27. public byte[] Values;
  28. };
  29. public struct ErrorInfo
  30. {
  31. public int ErrorCode;
  32. public string Command;
  33. public string ErrorMessage;
  34. }
  35. public enum SCLCommandEncodingTable
  36. {
  37. AlarmReset = 0xBA,
  38. StartJogging = 0x96,
  39. StopJogging = 0xD8,
  40. EncoderFunction = 0xD6,
  41. EncoderPosition = 0x98,
  42. FeedtoDoubleSensor = 0x69,
  43. FollowEncoder = 0xCC,
  44. FeedtoLength = 0x66,
  45. FeedtoSensorwithMaskDistance = 0x6A,
  46. FeedandSetOutput = 0x68,
  47. FeedtoPosition = 0x67,
  48. FeedtoSensor = 0x6B,
  49. FeedtoSensorwithSafetyDistance = 0x6C,
  50. JogDisable = 0xA3,
  51. JogEnable = 0xA2,
  52. MotorDisable = 0x9E,
  53. MotorEnable = 0x9F,
  54. SeekHome = 0x6E,
  55. SetPosition = 0xA5,
  56. FilterInput = 0xC0,
  57. FilterSelectInputs = 0xD3,
  58. StepFilterFreq = 0x06,
  59. WriteAnalogDeadband = 0xD2,
  60. WriteAlarmResetInput = 0x46,
  61. WriteAlarmOutput = 0x47,
  62. WriteAnalogScaling = 0xD1,
  63. WriteDefineLimits = 0x42,
  64. SetOutput = 0x8B,
  65. WriteWaitforInput = 0x70,
  66. QueueLoadAndExecute = 0x78,
  67. WriteWaitTime = 0x6F,
  68. StopAndKill = 0xE1,
  69. StopAndKillWithNormalDecel = 0xE2,
  70. }
  71. public class ModbusRTU
  72. {
  73. //if (Environment.Is64BitOperatingSystem)
  74. //? "Resources/ModbusRTU_x86.dll" :
  75. private const string DLL_FILENAME = "Lib/ModbusRTU_x86.dll"; // for 64-bit windows, please comment this line and uncomment next line
  76. //private const string DLL_FILENAME = "ModbusRTU_x64.dll"; // for 32-bit windows,, please comment this line and uncomment previous line
  77. private byte m_COMPort = 1;
  78. public byte COMPort
  79. {
  80. get
  81. {
  82. return m_COMPort;
  83. }
  84. }
  85. #region public fields
  86. //standard specific
  87. public int MBERROR_ILLEGAL_FUNCTION = 0x01;
  88. public int MBERROR_ILLEGAL_DATA_ADDRESS = 0x02;
  89. public int MBERROR_ILLEGAL_DATA_VALUE = 0x03;
  90. public int MBERROR_SLAVE_DEVICE_FAILURE = 0x04;
  91. public int MBERROR_ACKNOWLEDGE = 0x05;
  92. public int MBERROR_SLAVE_DEVICE_BUSY = 0x06;
  93. public int MBERROR_NEGATIVE_ACKNOWLEDGE = 0x07;
  94. public int MBERROR_MEMORY_PARITY_ERROR = 0x08;
  95. public int MBERROR_GATEWAY_PATH_UNAVAILABLE = 0x0A;
  96. public int MBERROR_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 0x0B;
  97. //manufacture specific
  98. public int MBERROR_CAN_NOT_READ = 0x11;
  99. public int MBERROR_CAN_NOT_WRITE = 0x12;
  100. public int MBERROR_DATA_RANG = 0x13;
  101. //other
  102. public int MBERROR_FAIL_TO_OPEN_PORT = 0x100;
  103. public int MBERROR_PORT_IS_CLOSED = 0x101;
  104. public int MBERROR_SEND_FAILED = 0x102;
  105. public int MBERROR_THREAD_ERROR = 0x103;
  106. public int MBERROR_NO_RESPONSE = 0x104;
  107. public int MBERROR_DATA_NOT_ENOUGH = 0x105;
  108. public int MBERROR_CRC_ERROR = 0x106;
  109. public int MBERROR_SCLREGISTER_NOTFOUND = 0x107;
  110. public int MBERROR_UNKNOWN_EXCEPTION = 0xFFFF;
  111. #endregion
  112. #region DllImport
  113. // Trigger when send data to drive
  114. [DllImport(DLL_FILENAME, EntryPoint = "OnDataSend", CharSet = CharSet.Auto)]
  115. private static extern void _OnDataSend(CSCallback func);
  116. // Trigger when received data from drive
  117. [DllImport(DLL_FILENAME, EntryPoint = "OnDataReceive", CharSet = CharSet.Auto)]
  118. private static extern void _OnDataReceive(CSCallback func);
  119. // Get the port is open or closed
  120. [DllImport(DLL_FILENAME, EntryPoint = "IsOpen", CharSet = CharSet.Auto)]
  121. private static extern bool _IsOpen(byte nCOMPort);
  122. // Open serial port communication
  123. [DllImport(DLL_FILENAME, EntryPoint = "Open", CharSet = CharSet.Auto)]
  124. private static extern bool _Open(byte nCOMPort, int nBaudRate, bool bBigEndian);
  125. // Close serial port communication
  126. [DllImport(DLL_FILENAME, EntryPoint = "Close", CharSet = CharSet.Auto)]
  127. private static extern bool _Close(byte nCOMPort);
  128. // Set endian type
  129. [DllImport(DLL_FILENAME, EntryPoint = "SetEndianType", CharSet = CharSet.Auto)]
  130. private static extern void _SetEndianType(byte nCOMPort, bool bBigEndian);
  131. // Return it is big endian type or not
  132. [DllImport(DLL_FILENAME, EntryPoint = "IsBigEndian", CharSet = CharSet.Auto)]
  133. private static extern bool _IsBigEndian(byte nCOMPort);
  134. // Get execute time out
  135. [DllImport(DLL_FILENAME, EntryPoint = "GetExecuteTimeOut", CharSet = CharSet.Auto)]
  136. private static extern uint _GetExecuteTimeOut(byte nCOMPort);
  137. // Set execute time out
  138. [DllImport(DLL_FILENAME, EntryPoint = "SetExecuteTimeOut", CharSet = CharSet.Auto)]
  139. private static extern void _SetExecuteTimeOut(byte nCOMPort, uint nExecuteTimeOut);
  140. // Set it will trigger send event or not when sending command
  141. [DllImport(DLL_FILENAME, EntryPoint = "SetTriggerSendEvent", CharSet = CharSet.Auto)]
  142. private static extern void _SetTriggerSendEvent(bool bTriggerSendEvent);
  143. // Set it will trigger received event or not when receive data
  144. [DllImport(DLL_FILENAME, EntryPoint = "SetTriggerReceiveEvent", CharSet = CharSet.Auto)]
  145. private static extern void _SetTriggerReceiveEvent(bool bTriggerReceiveEvent);
  146. // Clear send buffer
  147. [DllImport(DLL_FILENAME, EntryPoint = "ClearSendBuffer", CharSet = CharSet.Auto)]
  148. private static extern void _ClearSendBuffer(byte nCOMPort);
  149. // Clear received buffer
  150. [DllImport(DLL_FILENAME, EntryPoint = "ClearReceivedBuffer", CharSet = CharSet.Auto)]
  151. private static extern void _ClearReceivedBuffer(byte nCOMPort);
  152. // Clear send and received Buffer
  153. [DllImport(DLL_FILENAME, EntryPoint = "ClearBuffer", CharSet = CharSet.Auto)]
  154. private static extern void _ClearBuffer(byte nCOMPort);
  155. // Get last error information, includes code and description
  156. [DllImport(DLL_FILENAME, EntryPoint = "GetLastErrorInfo", CharSet = CharSet.Ansi)]
  157. private static extern void _GetLastErrorInfo(ref ErrorInfo errorInfo);
  158. // Get the last command that send
  159. [DllImport(DLL_FILENAME, EntryPoint = "GetLastCommandSent", CharSet = CharSet.Auto)]
  160. private static extern bool _GetLastCommandSent(byte nCOMPort, IntPtr ptrCommandStu);
  161. // Get the last command that received
  162. [DllImport(DLL_FILENAME, EntryPoint = "GetLastCommandReceived", CharSet = CharSet.Auto)]
  163. private static extern bool _GetLastCommandReceived(byte nCOMPort, IntPtr ptrCommandStu);
  164. // Read single holding register from the drive
  165. [DllImport(DLL_FILENAME, EntryPoint = "ReadSingleHoldingRegister", CharSet = CharSet.Auto)]
  166. private static extern bool _ReadSingleHoldingRegister(byte nCOMPort, byte nNodeID, int registerNo, ref int value);
  167. // Write single holding register value to the drive
  168. [DllImport(DLL_FILENAME, EntryPoint = "WriteSingleHoldingRegister", CharSet = CharSet.Auto)]
  169. private static extern bool _WriteSingleHoldingRegister(byte nCOMPort, byte nNodeID, int registerNo, int value);
  170. // Read multiple holding register from the drive
  171. [DllImport(DLL_FILENAME, EntryPoint = "ReadMultiHoldingRegisters", CharSet = CharSet.Auto)]
  172. private static extern bool _ReadMultiHoldingRegisters(byte nCOMPort, byte nNodeID, int registerNo, int count, IntPtr ptrHoldingRegisterStu);
  173. // Write multiple holding register values to the drive
  174. [DllImport(DLL_FILENAME, EntryPoint = "WriteMultiHoldingRegisters", CharSet = CharSet.Auto)]
  175. private static extern bool _WriteMultiHoldingRegisters(byte nCOMPort, byte nNodeID, int registerNo, int count, [MarshalAs(UnmanagedType.LPArray, SizeConst = 100)] int[] valueList);
  176. // Read 16-bit int data from the drive
  177. [DllImport(DLL_FILENAME, EntryPoint = "ReadDataInt16", CharSet = CharSet.Auto)]
  178. private static extern bool _ReadDataInt16(byte nCOMPort, byte nNodeID, int nRegisterNo, ref short nValue);
  179. // Write 16-bit int data to the drive
  180. [DllImport(DLL_FILENAME, EntryPoint = "WriteDataInt16", CharSet = CharSet.Auto)]
  181. private static extern bool _WriteDataInt16(byte nCOMPort, byte nNodeID, int nRegisterNo, short nValue);
  182. // Read 16-bit unsighed int data from the drive
  183. [DllImport(DLL_FILENAME, EntryPoint = "ReadDataUInt16", CharSet = CharSet.Auto)]
  184. private static extern bool _ReadDataUInt16(byte nCOMPort, byte nNodeID, int nRegisterNo, ref ushort nValue);
  185. // Write 16-bit unsigned int data to the drive
  186. [DllImport(DLL_FILENAME, EntryPoint = "WriteDataUInt16", CharSet = CharSet.Auto)]
  187. private static extern bool _WriteDataUInt16(byte nCOMPort, byte nNodeID, int nRegisterNo, ushort nValue);
  188. // Read 32-bit int data from the drive
  189. [DllImport(DLL_FILENAME, EntryPoint = "ReadDataInt32", CharSet = CharSet.Auto)]
  190. private static extern bool _ReadDataInt32(byte nCOMPort, byte nNodeID, int nRegisterNo, ref int nValue);
  191. // Write 32-bit int data to the drive
  192. [DllImport(DLL_FILENAME, EntryPoint = "WriteDataInt32", CharSet = CharSet.Auto)]
  193. private static extern bool _WriteDataInt32(byte nCOMPort, byte nNodeID, int nRegisterNo, int nValue);
  194. // Read 32-bit unsighed int data from the drive
  195. [DllImport(DLL_FILENAME, EntryPoint = "ReadDataUInt32", CharSet = CharSet.Auto)]
  196. private static extern bool _ReadDataUInt32(byte nCOMPort, byte nNodeID, int nRegisterNo, ref uint nValue);
  197. // Write 32-bit unsigned int data to the drive
  198. [DllImport(DLL_FILENAME, EntryPoint = "WriteDataUInt32", CharSet = CharSet.Auto)]
  199. private static extern bool _WriteDataUInt32(byte nCOMPort, byte nNodeID, int nRegisterNo, uint nValue);
  200. // Execute command with opcode
  201. [DllImport(DLL_FILENAME, EntryPoint = "ExecuteCommandWithOpcode", CharSet = CharSet.Auto)]
  202. private static extern bool _ExecuteCommandWithOpcode(byte nCOMPort, byte nNodeID, int nOpCode, int nParam1, int nParam2, int nParam3, int nParam4, int nParam5);
  203. [DllImport(DLL_FILENAME, EntryPoint = "ExecuteSCLCommand", CharSet = CharSet.Ansi)]
  204. private static extern bool _ExecuteSCLCommand(byte nCOMPort, byte nNodeID, int registerNo, byte[] arrCommand, ref IntPtr ptrResponse);
  205. // Set P2P profile arguments
  206. [DllImport(DLL_FILENAME, EntryPoint = "SetP2PProfile", CharSet = CharSet.Auto)]
  207. private static extern bool _SetP2PProfile(byte nCOMPort, byte nNodeID, IntPtr dVelocity, IntPtr dAccel, IntPtr dDecel);
  208. // Set Jog profile arguments
  209. [DllImport(DLL_FILENAME, EntryPoint = "SetJogProfile", CharSet = CharSet.Auto)]
  210. private static extern bool _SetJogProfile(byte nCOMPort, byte nNodeID, IntPtr dVelocity, IntPtr dAccel, IntPtr dDecel);
  211. // Set the drive enabled or disabled
  212. [DllImport(DLL_FILENAME, EntryPoint = "DriveEnable", CharSet = CharSet.Auto)]
  213. private static extern bool _DriveEnable(byte nCOMPort, byte nNodeID, bool bEnable);
  214. // Reset drive's dlarm
  215. [DllImport(DLL_FILENAME, EntryPoint = "AlarmReset", CharSet = CharSet.Auto)]
  216. private static extern bool _AlarmReset(byte nCOMPort, byte nNodeID);
  217. // Launch feed to position move
  218. [DllImport(DLL_FILENAME, EntryPoint = "FeedtoPosition", CharSet = CharSet.Auto)]
  219. private static extern bool _FeedtoPosition(byte nCOMPort, byte nNodeID, IntPtr nDistance);
  220. // Launch feed to length move
  221. [DllImport(DLL_FILENAME, EntryPoint = "FeedtoLength", CharSet = CharSet.Auto)]
  222. private static extern bool _FeedtoLength(byte nCOMPort, byte nNodeID, IntPtr nDistance);
  223. [DllImport(DLL_FILENAME, EntryPoint = "AbsMove")]
  224. public static extern bool _AbsMove(byte nCOMPort, byte nNodeID, int nDistance, IntPtr dVelocity, IntPtr dAccel, IntPtr dDecel);
  225. [DllImport(DLL_FILENAME, EntryPoint = "RelMove")]
  226. public static extern bool _RelMove(byte nCOMPort, byte nNodeID, int nDistance, IntPtr dVelocity, IntPtr dAccel, IntPtr dDecel);
  227. // Launch feed to sensor move
  228. [DllImport(DLL_FILENAME, EntryPoint = "FeedtoSensor", CharSet = CharSet.Auto)]
  229. private static extern bool _FeedtoSensor(byte nCOMPort, byte nNodeID, byte nInputSensor, char chInputStatus);
  230. // Lanuch feed to sensor move with safety distance
  231. [DllImport(DLL_FILENAME, EntryPoint = "FeedtoSensorwithSafetyDistance", CharSet = CharSet.Auto)]
  232. private static extern bool _FeedtoSensorwithSafetyDistance(byte nCOMPort, byte nNodeID, byte nInputSensor, char chInputStatus);
  233. // Launch feed to double sensor move with mask distance
  234. [DllImport(DLL_FILENAME, EntryPoint = "FeedtoSensorwithMaskDistance", CharSet = CharSet.Auto)]
  235. private static extern bool _FeedtoSensorwithMaskDistance(byte nCOMPort, byte nNodeID, byte nInputSensor, char chInputStatus);
  236. // Launch Point to Point Move and set output
  237. [DllImport(DLL_FILENAME, EntryPoint = "FeedandSetOutput", CharSet = CharSet.Auto)]
  238. private static extern bool _FeedandSetOutput(byte nCOMPort, byte nNodeID, byte nOutput, char chOutputStatus);
  239. // Launch feed to double sensor move
  240. [DllImport(DLL_FILENAME, EntryPoint = "FeedtoDoubleSensor", CharSet = CharSet.Auto)]
  241. private static extern bool _FeedtoDoubleSensor(byte nCOMPort, byte nNodeID, byte nInput1, char chInputStatus1, byte nInput2, char chInputStatus2);
  242. // Launch follow encoder move
  243. [DllImport(DLL_FILENAME, EntryPoint = "FollowEncoder", CharSet = CharSet.Auto)]
  244. private static extern bool _FollowEncoder(byte nCOMPort, byte nNodeID, byte nInputSensor, char chInputStatus);
  245. // Commence Jogging
  246. [DllImport(DLL_FILENAME, EntryPoint = "StartJogging", CharSet = CharSet.Auto)]
  247. private static extern bool _StartJogging(byte nCOMPort, byte nNodeID);
  248. // Stop Jogging
  249. [DllImport(DLL_FILENAME, EntryPoint = "StopJogging", CharSet = CharSet.Auto)]
  250. private static extern bool _StopJogging(byte nCOMPort, byte nNodeID);
  251. // Set encoder function to the stepper drives with encoder feedback
  252. [DllImport(DLL_FILENAME, EntryPoint = "SetEncoderFunction", CharSet = CharSet.Auto)]
  253. private static extern bool _SetEncoderFunction(byte nCOMPort, byte nNodeID, byte nFunc);
  254. // Set encoder position
  255. [DllImport(DLL_FILENAME, EntryPoint = "SetEncoderPosition", CharSet = CharSet.Auto)]
  256. private static extern bool _SetEncoderPosition(byte nCOMPort, byte nNodeID, int nPosition);
  257. // Jog disable
  258. [DllImport(DLL_FILENAME, EntryPoint = "JogDisable", CharSet = CharSet.Auto)]
  259. private static extern bool _JogDisable(byte nCOMPort, byte nNodeID);
  260. // Jog enable
  261. [DllImport(DLL_FILENAME, EntryPoint = "JogEnable", CharSet = CharSet.Auto)]
  262. private static extern bool _JogEnable(byte nCOMPort, byte nNodeID);
  263. // Launch seek home move
  264. [DllImport(DLL_FILENAME, EntryPoint = "SeekHome", CharSet = CharSet.Auto)]
  265. private static extern bool _SeekHome(byte nCOMPort, byte nNodeID, byte nInputSensor, char chInputStatus);
  266. // Set position
  267. [DllImport(DLL_FILENAME, EntryPoint = "SetPosition", CharSet = CharSet.Auto)]
  268. private static extern bool _SetPosition(byte nCOMPort, byte nNodeID, int nPosition);
  269. // Set filter input
  270. [DllImport(DLL_FILENAME, EntryPoint = "SetFilterInput", CharSet = CharSet.Auto)]
  271. private static extern bool _SetFilterInput(byte nCOMPort, byte nNodeID, byte nInputSensor, int nFilterTime);
  272. // Write analog deadband
  273. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogDeadband", CharSet = CharSet.Auto)]
  274. private static extern bool _WriteAnalogDeadband(byte nCOMPort, byte nNodeID, byte nDeadband);
  275. // Set output of the drive
  276. [DllImport(DLL_FILENAME, EntryPoint = "SetOutput", CharSet = CharSet.Auto)]
  277. private static extern bool _SetOutput(byte nCOMPort, byte nNodeID, byte nOutput, char nCondition);
  278. // Write wait for input
  279. [DllImport(DLL_FILENAME, EntryPoint = "WriteWaitforInput", CharSet = CharSet.Auto)]
  280. private static extern bool _WriteWaitforInput(byte nCOMPort, byte nNodeID, byte nInputSensor, char nCondition);
  281. // Queue Load and Execute
  282. [DllImport(DLL_FILENAME, EntryPoint = "QueueLoadAndExecute", CharSet = CharSet.Auto)]
  283. private static extern bool _QueueLoadAndExecute(byte nCOMPort, byte nNodeID, byte nSegment);
  284. // Write wait time
  285. [DllImport(DLL_FILENAME, EntryPoint = "WriteWaitTime", CharSet = CharSet.Auto)]
  286. private static extern bool _WriteWaitTime(byte nCOMPort, byte nNodeID, ushort nTime);
  287. // Stop and kill current move
  288. [DllImport(DLL_FILENAME, EntryPoint = "StopAndKill", CharSet = CharSet.Auto)]
  289. private static extern bool _StopAndKill(byte nCOMPort, byte nNodeID);
  290. // Stop and kill current move with normal deceleration
  291. [DllImport(DLL_FILENAME, EntryPoint = "StopAndKillwithNormalDecel", CharSet = CharSet.Auto)]
  292. private static extern bool _StopAndKillwithNormalDecel(byte nCOMPort, byte nNodeID);
  293. // Set P2P profile arguments
  294. [DllImport(DLL_FILENAME, EntryPoint = "SetP2PProfile_M3", CharSet = CharSet.Auto)]
  295. private static extern bool _SetP2PProfile_M3(byte nCOMPort, byte nNodeID, IntPtr dVelocity, IntPtr dAccel, IntPtr dDecel);
  296. // Set Jog profile arguments
  297. [DllImport(DLL_FILENAME, EntryPoint = "SetJogProfile_M3", CharSet = CharSet.Auto)]
  298. private static extern bool _SetJogProfile_M3(byte nCOMPort, byte nNodeID, IntPtr dVelocity, IntPtr dAccel, IntPtr dDecel);
  299. // Set the drive enabled or disabled
  300. [DllImport(DLL_FILENAME, EntryPoint = "DriveEnable_M3", CharSet = CharSet.Auto)]
  301. private static extern bool _DriveEnable_M3(byte nCOMPort, byte nNodeID, bool bEnable);
  302. // Reset drive's dlarm
  303. [DllImport(DLL_FILENAME, EntryPoint = "AlarmReset_M3", CharSet = CharSet.Auto)]
  304. private static extern bool _AlarmReset_M3(byte nCOMPort, byte nNodeID);
  305. // Launch feed to position move
  306. [DllImport(DLL_FILENAME, EntryPoint = "FeedtoPosition_M3", CharSet = CharSet.Auto)]
  307. private static extern bool _FeedtoPosition_M3(byte nCOMPort, byte nNodeID, IntPtr nDistance);
  308. // Launch feed to length move
  309. [DllImport(DLL_FILENAME, EntryPoint = "FeedtoLength_M3", CharSet = CharSet.Auto)]
  310. private static extern bool _FeedtoLength_M3(byte nCOMPort, byte nNodeID, IntPtr nDistance);
  311. [DllImport(DLL_FILENAME, EntryPoint = "AbsMove_M3")]
  312. public static extern bool _AbsMove_M3(byte nCOMPort, byte nNodeID, int nDistance, IntPtr dVelocity, IntPtr dAccel, IntPtr dDecel);
  313. [DllImport(DLL_FILENAME, EntryPoint = "RelMove_M3")]
  314. public static extern bool _RelMove_M3(byte nCOMPort, byte nNodeID, int nDistance, IntPtr dVelocity, IntPtr dAccel, IntPtr dDecel);
  315. // Set Home profile
  316. [DllImport(DLL_FILENAME, EntryPoint = "SetHomeProfile", CharSet = CharSet.Auto)]
  317. private static extern bool _SetHomeProfile(byte nCOMPort, byte nNodeID, IntPtr dVelocity1, IntPtr dVelocity2, IntPtr dAccel, IntPtr nHomingOffset);
  318. // Set Home method
  319. [DllImport(DLL_FILENAME, EntryPoint = "SetHomeMethod", CharSet = CharSet.Auto)]
  320. private static extern bool _SetHomeMethod(byte nCOMPort, byte nNodeID, sbyte nHomeMethod);
  321. // Launch feed home move
  322. [DllImport(DLL_FILENAME, EntryPoint = "FeedHome", CharSet = CharSet.Auto)]
  323. private static extern bool _FeedHome(byte nCOMPort, byte nNodeID, sbyte nHomeMethod, IntPtr dVelocity1, IntPtr dVelocity2, IntPtr dAccel, IntPtr nHomingOffset);
  324. // Read alarm code
  325. [DllImport(DLL_FILENAME, EntryPoint = "ReadAlarmCode", CharSet = CharSet.Auto)]
  326. private static extern bool _ReadAlarmCode(byte nCOMPort, byte nNodeID, ref uint nAlarmCode);
  327. // Read status code
  328. [DllImport(DLL_FILENAME, EntryPoint = "ReadStatusCode", CharSet = CharSet.Auto)]
  329. private static extern bool _ReadStatusCode(byte nCOMPort, byte nNodeID, ref uint nStatusCode);
  330. // Read immediate expanded inputs
  331. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateExpandedInputs", CharSet = CharSet.Auto)]
  332. private static extern bool _ReadImmediateExpandedInputs(byte nCOMPort, byte nNodeID, ref ushort nInputsStatus);
  333. // Read driver board inputs
  334. [DllImport(DLL_FILENAME, EntryPoint = "ReadDriverBoardInputs", CharSet = CharSet.Auto)]
  335. private static extern bool _ReadDriverBoardInputs(byte nCOMPort, byte nNodeID, ref ushort nInputsStatus);
  336. // Read encoder position
  337. [DllImport(DLL_FILENAME, EntryPoint = "ReadEncoderPosition", CharSet = CharSet.Auto)]
  338. private static extern bool _ReadEncoderPosition(byte nCOMPort, byte nNodeID, ref int nEncoderPosition);
  339. // Read immediate absolute position
  340. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAbsolutePosition", CharSet = CharSet.Auto)]
  341. private static extern bool _ReadImmediateAbsolutePosition(byte nCOMPort, byte nNodeID, ref int nImmediateAbsolutePosition);
  342. // Read immediate actual velocity
  343. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateActualVelocity", CharSet = CharSet.Auto)]
  344. private static extern bool _ReadImmediateActualVelocity(byte nCOMPort, byte nNodeID, ref double dImmediateActualVelocity);
  345. // Read immediate target velocity
  346. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateTargetVelocity", CharSet = CharSet.Auto)]
  347. private static extern bool _ReadImmediateTargetVelocity(byte nCOMPort, byte nNodeID, ref double dImmediateTargetVelocity);
  348. // Read immediate drive temperature
  349. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateDriveTemperature", CharSet = CharSet.Auto)]
  350. private static extern bool _ReadImmediateDriveTemperature(byte nCOMPort, byte nNodeID, ref double dImmediateDriveTemperature);
  351. // Read immediate bus voltage
  352. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateBusVoltage", CharSet = CharSet.Auto)]
  353. private static extern bool _ReadImmediateBusVoltage(byte nCOMPort, byte nNodeID, ref double dImmediateBusVoltage);
  354. // Read immediate position error
  355. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediatePositionError", CharSet = CharSet.Auto)]
  356. private static extern bool _ReadImmediatePositionError(byte nCOMPort, byte nNodeID, ref int nImmediatePositionError);
  357. // Read immediate analog input value
  358. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAnalogInputValue", CharSet = CharSet.Auto)]
  359. private static extern bool _ReadImmediateAnalogInputValue(byte nCOMPort, byte nNodeID, ref short nImmediateAnalogInputValue);
  360. // Read immediate analog input1 Value
  361. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAnalogInput1Value", CharSet = CharSet.Auto)]
  362. private static extern bool _ReadImmediateAnalogInput1Value(byte nCOMPort, byte nNodeID, ref short nImmediateAnalogInputValue);
  363. // Read immediate analog input2 Value
  364. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAnalogInput2Value", CharSet = CharSet.Auto)]
  365. private static extern bool _ReadImmediateAnalogInput2Value(byte nCOMPort, byte nNodeID, ref short nImmediateAnalogInputValue);
  366. // Read Q program line number
  367. [DllImport(DLL_FILENAME, EntryPoint = "ReadQProgramLineNumber", CharSet = CharSet.Auto)]
  368. private static extern bool _ReadQProgramLineNumber(byte nCOMPort, byte nNodeID, ref ushort nQProgramLineNumber);
  369. // Read immediate current command
  370. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateCurrentCommand", CharSet = CharSet.Auto)]
  371. private static extern bool _ReadImmediateCurrentCommand(byte nCOMPort, byte nNodeID, ref short nImmediateCurrentCommand);
  372. // Read relative distance
  373. [DllImport(DLL_FILENAME, EntryPoint = "ReadRelativeDistance", CharSet = CharSet.Auto)]
  374. private static extern bool _ReadRelativeDistance(byte nCOMPort, byte nNodeID, ref int nRelativeDistance);
  375. // Read sensor position
  376. [DllImport(DLL_FILENAME, EntryPoint = "ReadSensorPosition", CharSet = CharSet.Auto)]
  377. private static extern bool _ReadSensorPosition(byte nCOMPort, byte nNodeID, ref int nSensorPosition);
  378. // Read condition code
  379. [DllImport(DLL_FILENAME, EntryPoint = "ReadConditionCode", CharSet = CharSet.Auto)]
  380. private static extern bool _ReadConditionCode(byte nCOMPort, byte nNodeID, ref ushort nConditionCode);
  381. // Read command mode
  382. [DllImport(DLL_FILENAME, EntryPoint = "ReadCommandMode", CharSet = CharSet.Auto)]
  383. private static extern bool _ReadCommandMode(byte nCOMPort, byte nNodeID, ref ushort nCommandMode);
  384. // Read distance or position
  385. [DllImport(DLL_FILENAME, EntryPoint = "ReadDistanceOrPosition", CharSet = CharSet.Auto)]
  386. private static extern bool _ReadDistanceOrPosition(byte nCOMPort, byte nNodeID, ref int nDistanceOrPosition);
  387. // Write distance or position
  388. [DllImport(DLL_FILENAME, EntryPoint = "WriteDistanceOrPosition", CharSet = CharSet.Auto)]
  389. private static extern bool _WriteDistanceOrPosition(byte nCOMPort, byte nNodeID, int nDistanceOrPosition);
  390. // Read change distance
  391. [DllImport(DLL_FILENAME, EntryPoint = "ReadChangeDistance", CharSet = CharSet.Auto)]
  392. private static extern bool _ReadChangeDistance(byte nCOMPort, byte nNodeID, ref int nChangeDistance);
  393. // Write change distance
  394. [DllImport(DLL_FILENAME, EntryPoint = "WriteChangeDistance", CharSet = CharSet.Auto)]
  395. private static extern bool _WriteChangeDistance(byte nCOMPort, byte nNodeID, int nChangeDistance);
  396. // Read change velocity
  397. [DllImport(DLL_FILENAME, EntryPoint = "ReadChangeVelocity", CharSet = CharSet.Auto)]
  398. private static extern bool _ReadChangeVelocity(byte nCOMPort, byte nNodeID, ref double dChangeVelocity);
  399. // Write change velocity
  400. [DllImport(DLL_FILENAME, EntryPoint = "WriteChangeVelocity", CharSet = CharSet.Auto)]
  401. private static extern bool _WriteChangeVelocity(byte nCOMPort, byte nNodeID, double dChangeVelocity);
  402. // Read velocity move state
  403. [DllImport(DLL_FILENAME, EntryPoint = "ReadVelocityMoveState", CharSet = CharSet.Auto)]
  404. private static extern bool _ReadVelocityMoveState(byte nCOMPort, byte nNodeID, ref ushort nVelocityMoveState);
  405. // Read P2P move state
  406. [DllImport(DLL_FILENAME, EntryPoint = "ReadP2PMoveState", CharSet = CharSet.Auto)]
  407. private static extern bool _ReadP2PMoveState(byte nCOMPort, byte nNodeID, ref ushort nP2PMoveState);
  408. // Read Q program segment number
  409. [DllImport(DLL_FILENAME, EntryPoint = "ReadQProgramSegmentNumber", CharSet = CharSet.Auto)]
  410. private static extern bool _ReadQProgramSegmentNumber(byte nCOMPort, byte nNodeID, ref ushort nQProgramSegmentNumber);
  411. // Read position offset
  412. [DllImport(DLL_FILENAME, EntryPoint = "ReadPositionOffset", CharSet = CharSet.Auto)]
  413. private static extern bool _ReadPositionOffset(byte nCOMPort, byte nNodeID, ref int nPositionOffset);
  414. // Write position offset
  415. [DllImport(DLL_FILENAME, EntryPoint = "WritePositionOffset", CharSet = CharSet.Auto)]
  416. private static extern bool _WritePositionOffset(byte nCOMPort, byte nNodeID, int nPositionOffset);
  417. // Read running current
  418. [DllImport(DLL_FILENAME, EntryPoint = "ReadRunningCurrent", CharSet = CharSet.Auto)]
  419. private static extern bool _ReadRunningCurrent(byte nCOMPort, byte nNodeID, ref double dRunningCurrent);
  420. // Write running current
  421. [DllImport(DLL_FILENAME, EntryPoint = "WriteRunningCurrent", CharSet = CharSet.Auto)]
  422. private static extern bool _WriteRunningCurrent(byte nCOMPort, byte nNodeID, double dRunningCurrent);
  423. // Read electronic gearing
  424. [DllImport(DLL_FILENAME, EntryPoint = "ReadElectronicGearing", CharSet = CharSet.Auto)]
  425. private static extern bool _ReadElectronicGearing(byte nCOMPort, byte nNodeID, ref ushort nElectronicGearing);
  426. // Write electronic gearing
  427. [DllImport(DLL_FILENAME, EntryPoint = "WriteElectronicGearing", CharSet = CharSet.Auto)]
  428. private static extern bool _WriteElectronicGearing(byte nCOMPort, byte nNodeID, ushort nElectronicGearing);
  429. // Read pulse counter
  430. [DllImport(DLL_FILENAME, EntryPoint = "ReadPulseCounter", CharSet = CharSet.Auto)]
  431. private static extern bool _ReadPulseCounter(byte nCOMPort, byte nNodeID, ref int nPulseCounter);
  432. // Write pulse counter
  433. [DllImport(DLL_FILENAME, EntryPoint = "WritePulseCounter", CharSet = CharSet.Auto)]
  434. private static extern bool _WritePulseCounter(byte nCOMPort, byte nNodeID, int nPulseCounter);
  435. // Read analog position gain
  436. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogPositionGain", CharSet = CharSet.Auto)]
  437. private static extern bool _ReadAnalogPositionGain(byte nCOMPort, byte nNodeID, ref ushort nAnalogPositionGain);
  438. // Write analog position gain
  439. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogPositionGain", CharSet = CharSet.Auto)]
  440. private static extern bool _WriteAnalogPositionGain(byte nCOMPort, byte nNodeID, ushort nAnalogPositionGain);
  441. // Read analog threshold
  442. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogThreshold", CharSet = CharSet.Auto)]
  443. private static extern bool _ReadAnalogThreshold(byte nCOMPort, byte nNodeID, ref ushort nAnalogThreshold);
  444. // Write analog threshold
  445. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogThreshold", CharSet = CharSet.Auto)]
  446. private static extern bool _WriteAnalogThreshold(byte nCOMPort, byte nNodeID, ushort nAnalogThreshold);
  447. // Read analogoffset
  448. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogOffset", CharSet = CharSet.Auto)]
  449. private static extern bool _ReadAnalogOffset(byte nCOMPort, byte nNodeID, ref ushort nAnalogOffset);
  450. // Write analog offset
  451. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogOffset", CharSet = CharSet.Auto)]
  452. private static extern bool _WriteAnalogOffset(byte nCOMPort, byte nNodeID, ushort nAnalogOffset);
  453. // Read accumulator
  454. [DllImport(DLL_FILENAME, EntryPoint = "ReadAccumulator", CharSet = CharSet.Auto)]
  455. private static extern bool _ReadAccumulator(byte nCOMPort, byte nNodeID, ref int nAccumulator);
  456. // Read user defined register
  457. [DllImport(DLL_FILENAME, EntryPoint = "ReadUserDefinedRegister", CharSet = CharSet.Auto)]
  458. private static extern bool _ReadUserDefinedRegister(byte nCOMPort, byte nNodeID, char chRegister, ref int nValue);
  459. // Write user defined register
  460. [DllImport(DLL_FILENAME, EntryPoint = "WriteUserDefinedRegister", CharSet = CharSet.Auto)]
  461. private static extern bool _WriteUserDefinedRegister(byte nCOMPort, byte nNodeID, char chRegister, int nValue);
  462. // Read brake release delay
  463. [DllImport(DLL_FILENAME, EntryPoint = "ReadBrakeReleaseDelay", CharSet = CharSet.Auto)]
  464. private static extern bool _ReadBrakeReleaseDelay(byte nCOMPort, byte nNodeID, ref double dBrakeReleaseDelay);
  465. // Write brake release delay
  466. [DllImport(DLL_FILENAME, EntryPoint = "WriteBrakeReleaseDelay", CharSet = CharSet.Auto)]
  467. private static extern bool _WriteBrakeReleaseDelay(byte nCOMPort, byte nNodeID, double dBrakeReleaseDelay);
  468. // Read brake engage delay
  469. [DllImport(DLL_FILENAME, EntryPoint = "ReadBrakeEngageDelay", CharSet = CharSet.Auto)]
  470. private static extern bool _ReadBrakeEngageDelay(byte nCOMPort, byte nNodeID, ref double dBrakeEngageDelay);
  471. // Write brake engage delay
  472. [DllImport(DLL_FILENAME, EntryPoint = "WriteBrakeEngageDelay", CharSet = CharSet.Auto)]
  473. private static extern bool _WriteBrakeEngageDelay(byte nCOMPort, byte nNodeID, double dBrakeEngageDelay);
  474. // Read analog filter gain
  475. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogFilterGain", CharSet = CharSet.Auto)]
  476. private static extern bool _ReadAnalogFilterGain(byte nCOMPort, byte nNodeID, ref ushort nAnalogFilterGain);
  477. // Write analog filter gain
  478. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogFilterGain", CharSet = CharSet.Auto)]
  479. private static extern bool _WriteAnalogFilterGain(byte nCOMPort, byte nNodeID, ushort nAnalogFilterGain);
  480. // Read alarm code
  481. [DllImport(DLL_FILENAME, EntryPoint = "ReadAlarmCode_M3", CharSet = CharSet.Auto)]
  482. private static extern bool _ReadAlarmCode_M3(byte nCOMPort, byte nNodeID, ref uint nAlarmCode);
  483. // Read status code
  484. [DllImport(DLL_FILENAME, EntryPoint = "ReadStatusCode_M3", CharSet = CharSet.Auto)]
  485. private static extern bool _ReadStatusCode_M3(byte nCOMPort, byte nNodeID, ref uint nStatusCode);
  486. // Read driver board inputs
  487. [DllImport(DLL_FILENAME, EntryPoint = "ReadDriverBoardInputs_M3", CharSet = CharSet.Auto)]
  488. private static extern bool _ReadDriverBoardInputs_M3(byte nCOMPort, byte nNodeID, ref ushort nInputsStatus);
  489. // Read driver board Outputs
  490. [DllImport(DLL_FILENAME, EntryPoint = "ReadDriverBoardOutputs_M3", CharSet = CharSet.Auto)]
  491. private static extern bool _ReadDriverBoardOutputs_M3(byte nCOMPort, byte nNodeID, ref ushort nOutputsStatus);
  492. // Read encoder position
  493. [DllImport(DLL_FILENAME, EntryPoint = "ReadEncoderPosition_M3", CharSet = CharSet.Auto)]
  494. private static extern bool _ReadEncoderPosition_M3(byte nCOMPort, byte nNodeID, ref int nEncoderPosition);
  495. // Read encoder position
  496. [DllImport(DLL_FILENAME, EntryPoint = "Read2ndEncoderPosition_M3", CharSet = CharSet.Auto)]
  497. private static extern bool _Read2ndEncoderPosition_M3(byte nCOMPort, byte nNodeID, ref int nEncoderPosition);
  498. // Read immediate absolute position
  499. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAbsolutePosition_M3", CharSet = CharSet.Auto)]
  500. private static extern bool _ReadImmediateAbsolutePosition_M3(byte nCOMPort, byte nNodeID, ref int nImmediateAbsolutePosition);
  501. // Read immediate actual velocity
  502. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateActualVelocity_M3", CharSet = CharSet.Auto)]
  503. private static extern bool _ReadImmediateActualVelocity_M3(byte nCOMPort, byte nNodeID, ref double dImmediateActualVelocity);
  504. // Read immediate target velocity
  505. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateTargetVelocity_M3", CharSet = CharSet.Auto)]
  506. private static extern bool _ReadImmediateTargetVelocity_M3(byte nCOMPort, byte nNodeID, ref double dImmediateTargetVelocity);
  507. // Read immediate drive temperature
  508. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateDriveTemperature_M3", CharSet = CharSet.Auto)]
  509. private static extern bool _ReadImmediateDriveTemperature_M3(byte nCOMPort, byte nNodeID, ref double dImmediateDriveTemperature);
  510. // Read immediate bus voltage
  511. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateBusVoltage_M3", CharSet = CharSet.Auto)]
  512. private static extern bool _ReadImmediateBusVoltage_M3(byte nCOMPort, byte nNodeID, ref double dImmediateBusVoltage);
  513. // Read immediate position error
  514. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediatePositionError_M3", CharSet = CharSet.Auto)]
  515. private static extern bool _ReadImmediatePositionError_M3(byte nCOMPort, byte nNodeID, ref int nImmediatePositionError);
  516. // Read immediate analog input1 Value
  517. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAnalogInput1Value_M3", CharSet = CharSet.Auto)]
  518. private static extern bool _ReadImmediateAnalogInput1Value_M3(byte nCOMPort, byte nNodeID, ref short nImmediateAnalogInputValue);
  519. // Read immediate analog input2 Value
  520. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAnalogInput2Value_M3", CharSet = CharSet.Auto)]
  521. private static extern bool _ReadImmediateAnalogInput2Value_M3(byte nCOMPort, byte nNodeID, ref short nImmediateAnalogInputValue);
  522. // Read immediate analog Output1 Value
  523. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAnalogOutput1Value_M3", CharSet = CharSet.Auto)]
  524. private static extern bool _ReadImmediateAnalogOutput1Value_M3(byte nCOMPort, byte nNodeID, ref short nImmediateAnalogOutputValue);
  525. // Write immediate analog Output1 Value
  526. [DllImport(DLL_FILENAME, EntryPoint = "WriteImmediateAnalogOutput1Value_M3", CharSet = CharSet.Auto)]
  527. private static extern bool _WriteImmediateAnalogOutput1Value_M3(byte nCOMPort, byte nNodeID, short nImmediateAnalogOutputValue);
  528. // Read immediate analog Output2 Value
  529. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateAnalogOutput2Value_M3", CharSet = CharSet.Auto)]
  530. private static extern bool _ReadImmediateAnalogOutput2Value_M3(byte nCOMPort, byte nNodeID, ref short nImmediateAnalogOutputValue);
  531. // Write immediate analog Output2 Value
  532. [DllImport(DLL_FILENAME, EntryPoint = "WriteImmediateAnalogOutput2Value_M3", CharSet = CharSet.Auto)]
  533. private static extern bool _WriteImmediateAnalogOutput2Value_M3(byte nCOMPort, byte nNodeID, short nImmediateAnalogOutputValue);
  534. // Read Q program line number
  535. [DllImport(DLL_FILENAME, EntryPoint = "ReadQProgramLineNumber_M3", CharSet = CharSet.Auto)]
  536. private static extern bool _ReadQProgramLineNumber_M3(byte nCOMPort, byte nNodeID, ref ushort nQProgramLineNumber);
  537. // Read immediate current command
  538. [DllImport(DLL_FILENAME, EntryPoint = "ReadImmediateCurrentCommand_M3", CharSet = CharSet.Auto)]
  539. private static extern bool _ReadImmediateCurrentCommand_M3(byte nCOMPort, byte nNodeID, ref short nImmediateCurrentCommand);
  540. // Read relative distance
  541. [DllImport(DLL_FILENAME, EntryPoint = "ReadRelativeDistance_M3", CharSet = CharSet.Auto)]
  542. private static extern bool _ReadRelativeDistance_M3(byte nCOMPort, byte nNodeID, ref int nRelativeDistance);
  543. // Read sensor position
  544. [DllImport(DLL_FILENAME, EntryPoint = "ReadSensorPosition_M3", CharSet = CharSet.Auto)]
  545. private static extern bool _ReadSensorPosition_M3(byte nCOMPort, byte nNodeID, ref int nSensorPosition);
  546. // Read condition code
  547. [DllImport(DLL_FILENAME, EntryPoint = "ReadConditionCode_M3", CharSet = CharSet.Auto)]
  548. private static extern bool _ReadConditionCode_M3(byte nCOMPort, byte nNodeID, ref ushort nConditionCode);
  549. // Read command mode
  550. [DllImport(DLL_FILENAME, EntryPoint = "ReadCommandMode_M3", CharSet = CharSet.Auto)]
  551. private static extern bool _ReadCommandMode_M3(byte nCOMPort, byte nNodeID, ref ushort nCommandMode);
  552. // Read distance or position
  553. [DllImport(DLL_FILENAME, EntryPoint = "ReadDistanceOrPosition_M3", CharSet = CharSet.Auto)]
  554. private static extern bool _ReadDistanceOrPosition_M3(byte nCOMPort, byte nNodeID, ref int nDistanceOrPosition);
  555. // Write distance or position
  556. [DllImport(DLL_FILENAME, EntryPoint = "WriteDistanceOrPosition_M3", CharSet = CharSet.Auto)]
  557. private static extern bool _WriteDistanceOrPosition_M3(byte nCOMPort, byte nNodeID, int nDistanceOrPosition);
  558. // Read change distance
  559. [DllImport(DLL_FILENAME, EntryPoint = "ReadChangeDistance_M3", CharSet = CharSet.Auto)]
  560. private static extern bool _ReadChangeDistance_M3(byte nCOMPort, byte nNodeID, ref int nChangeDistance);
  561. // Write change distance
  562. [DllImport(DLL_FILENAME, EntryPoint = "WriteChangeDistance_M3", CharSet = CharSet.Auto)]
  563. private static extern bool _WriteChangeDistance_M3(byte nCOMPort, byte nNodeID, int nChangeDistance);
  564. // Read change velocity
  565. [DllImport(DLL_FILENAME, EntryPoint = "ReadChangeVelocity_M3", CharSet = CharSet.Auto)]
  566. private static extern bool _ReadChangeVelocity_M3(byte nCOMPort, byte nNodeID, ref double dChangeVelocity);
  567. // Write change velocity
  568. [DllImport(DLL_FILENAME, EntryPoint = "WriteChangeVelocity_M3", CharSet = CharSet.Auto)]
  569. private static extern bool _WriteChangeVelocity_M3(byte nCOMPort, byte nNodeID, double dChangeVelocity);
  570. // Read velocity move state
  571. [DllImport(DLL_FILENAME, EntryPoint = "ReadVelocityMoveState_M3", CharSet = CharSet.Auto)]
  572. private static extern bool _ReadVelocityMoveState_M3(byte nCOMPort, byte nNodeID, ref ushort nVelocityMoveState);
  573. // Read P2P move state
  574. [DllImport(DLL_FILENAME, EntryPoint = "ReadP2PMoveState_M3", CharSet = CharSet.Auto)]
  575. private static extern bool _ReadP2PMoveState_M3(byte nCOMPort, byte nNodeID, ref ushort nP2PMoveState);
  576. // Read Q program segment number
  577. [DllImport(DLL_FILENAME, EntryPoint = "ReadQProgramSegmentNumber_M3", CharSet = CharSet.Auto)]
  578. private static extern bool _ReadQProgramSegmentNumber_M3(byte nCOMPort, byte nNodeID, ref ushort nQProgramSegmentNumber);
  579. // Read Command current
  580. [DllImport(DLL_FILENAME, EntryPoint = "ReadCommandCurrent_M3", CharSet = CharSet.Auto)]
  581. private static extern bool _ReadCommandCurrent_M3(byte nCOMPort, byte nNodeID, ref double dCommandCurrent);
  582. // Write Command current
  583. [DllImport(DLL_FILENAME, EntryPoint = "WriteCommandCurrent_M3", CharSet = CharSet.Auto)]
  584. private static extern bool _WriteCommandCurrent_M3(byte nCOMPort, byte nNodeID, double dCommandCurrent);
  585. // Read Max current
  586. [DllImport(DLL_FILENAME, EntryPoint = "ReadMaximumCurrent_M3", CharSet = CharSet.Auto)]
  587. private static extern bool _ReadMaximumCurrent_M3(byte nCOMPort, byte nNodeID, ref double dMaximumCurrent);
  588. // Write Max current
  589. [DllImport(DLL_FILENAME, EntryPoint = "WriteMaximumCurrent_M3", CharSet = CharSet.Auto)]
  590. private static extern bool _WriteMaximumCurrent_M3(byte nCOMPort, byte nNodeID, double dMaximumCurrent);
  591. // Read electronic gearing
  592. [DllImport(DLL_FILENAME, EntryPoint = "ReadElectronicGearing_M3", CharSet = CharSet.Auto)]
  593. private static extern bool _ReadElectronicGearing_M3(byte nCOMPort, byte nNodeID, ref uint nElectronicGearing);
  594. // Write electronic gearing
  595. [DllImport(DLL_FILENAME, EntryPoint = "WriteElectronicGearing_M3", CharSet = CharSet.Auto)]
  596. private static extern bool _WriteElectronicGearing_M3(byte nCOMPort, byte nNodeID, uint nElectronicGearing);
  597. // Read pulse counter
  598. [DllImport(DLL_FILENAME, EntryPoint = "ReadPulseCounter_M3", CharSet = CharSet.Auto)]
  599. private static extern bool _ReadPulseCounter_M3(byte nCOMPort, byte nNodeID, ref int nPulseCounter);
  600. // Write pulse counter
  601. [DllImport(DLL_FILENAME, EntryPoint = "WritePulseCounter_M3", CharSet = CharSet.Auto)]
  602. private static extern bool _WritePulseCounter_M3(byte nCOMPort, byte nNodeID, int nPulseCounter);
  603. // Read analog position gain
  604. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogPositionGain_M3", CharSet = CharSet.Auto)]
  605. private static extern bool _ReadAnalogPositionGain_M3(byte nCOMPort, byte nNodeID, ref int nAnalogPositionGain);
  606. // Write analog position gain
  607. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogPositionGain_M3", CharSet = CharSet.Auto)]
  608. private static extern bool _WriteAnalogPositionGain_M3(byte nCOMPort, byte nNodeID, int nAnalogPositionGain);
  609. // Read analog velocity gain
  610. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogVelocityGain_M3", CharSet = CharSet.Auto)]
  611. private static extern bool _ReadAnalogVelocityGain_M3(byte nCOMPort, byte nNodeID, ref double nAnalogVelocityGain);
  612. // Write analog velocity gain
  613. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogVelocityGain_M3", CharSet = CharSet.Auto)]
  614. private static extern bool _WriteAnalogVelocityGain_M3(byte nCOMPort, byte nNodeID, double nAnalogVelocityGain);
  615. // Read analog torque gain
  616. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogTorqueGain_M3", CharSet = CharSet.Auto)]
  617. private static extern bool _ReadAnalogTorqueGain_M3(byte nCOMPort, byte nNodeID, ref double nAnalogTorqueGain);
  618. // Write analog torque gain
  619. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogTorqueGain_M3", CharSet = CharSet.Auto)]
  620. private static extern bool _WriteAnalogTorqueGain_M3(byte nCOMPort, byte nNodeID, double nAnalogTorqueGain);
  621. // Read analog threshold
  622. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogThreshold1_M3", CharSet = CharSet.Auto)]
  623. private static extern bool _ReadAnalogThreshold1_M3(byte nCOMPort, byte nNodeID, ref int nAnalogThreshold);
  624. // Write analog threshold
  625. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogThreshold1_M3", CharSet = CharSet.Auto)]
  626. private static extern bool _WriteAnalogThreshold1_M3(byte nCOMPort, byte nNodeID, int nAnalogThreshold);
  627. // Read analog threshold
  628. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogThreshold2_M3", CharSet = CharSet.Auto)]
  629. private static extern bool _ReadAnalogThreshold2_M3(byte nCOMPort, byte nNodeID, ref int nAnalogThreshold);
  630. // Write analog threshold
  631. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogThreshold2_M3", CharSet = CharSet.Auto)]
  632. private static extern bool _WriteAnalogThreshold2_M3(byte nCOMPort, byte nNodeID, int nAnalogThreshold);
  633. // Read analogoffset
  634. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogOffset1_M3", CharSet = CharSet.Auto)]
  635. private static extern bool _ReadAnalogOffset1_M3(byte nCOMPort, byte nNodeID, ref int nAnalogOffset);
  636. // Write analog offset
  637. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogOffset1_M3", CharSet = CharSet.Auto)]
  638. private static extern bool _WriteAnalogOffset1_M3(byte nCOMPort, byte nNodeID, int nAnalogOffset);
  639. // Read analogoffset
  640. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogOffset2_M3", CharSet = CharSet.Auto)]
  641. private static extern bool _ReadAnalogOffset2_M3(byte nCOMPort, byte nNodeID, ref int nAnalogOffset);
  642. // Write analog offset
  643. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogOffset2_M3", CharSet = CharSet.Auto)]
  644. private static extern bool _WriteAnalogOffset2_M3(byte nCOMPort, byte nNodeID, int nAnalogOffset);
  645. // Read accumulator
  646. [DllImport(DLL_FILENAME, EntryPoint = "ReadAccumulator_M3", CharSet = CharSet.Auto)]
  647. private static extern bool _ReadAccumulator_M3(byte nCOMPort, byte nNodeID, ref int nAccumulator);
  648. // Read user defined register
  649. [DllImport(DLL_FILENAME, EntryPoint = "ReadUserDefinedRegister_M3", CharSet = CharSet.Auto)]
  650. private static extern bool _ReadUserDefinedRegister_M3(byte nCOMPort, byte nNodeID, char chRegister, ref int nValue);
  651. // Write user defined register
  652. [DllImport(DLL_FILENAME, EntryPoint = "WriteUserDefinedRegister_M3", CharSet = CharSet.Auto)]
  653. private static extern bool _WriteUserDefinedRegister_M3(byte nCOMPort, byte nNodeID, char chRegister, int nValue);
  654. // Read brake release delay
  655. [DllImport(DLL_FILENAME, EntryPoint = "ReadBrakeReleaseDelay_M3", CharSet = CharSet.Auto)]
  656. private static extern bool _ReadBrakeReleaseDelay_M3(byte nCOMPort, byte nNodeID, ref double dBrakeReleaseDelay);
  657. // Write brake release delay
  658. [DllImport(DLL_FILENAME, EntryPoint = "WriteBrakeReleaseDelay_M3", CharSet = CharSet.Auto)]
  659. private static extern bool _WriteBrakeReleaseDelay_M3(byte nCOMPort, byte nNodeID, double dBrakeReleaseDelay);
  660. // Read brake engage delay
  661. [DllImport(DLL_FILENAME, EntryPoint = "ReadBrakeEngageDelay_M3", CharSet = CharSet.Auto)]
  662. private static extern bool _ReadBrakeEngageDelay_M3(byte nCOMPort, byte nNodeID, ref double dBrakeEngageDelay);
  663. // Write brake engage delay
  664. [DllImport(DLL_FILENAME, EntryPoint = "WriteBrakeEngageDelay_M3", CharSet = CharSet.Auto)]
  665. private static extern bool _WriteBrakeEngageDelay_M3(byte nCOMPort, byte nNodeID, double dBrakeEngageDelay);
  666. // Read analog filter gain
  667. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogFilterGain1_M3", CharSet = CharSet.Auto)]
  668. private static extern bool _ReadAnalogFilterGain1_M3(byte nCOMPort, byte nNodeID, ref ushort nAnalogFilterGain);
  669. // Write analog filter gain
  670. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogFilterGain1_M3", CharSet = CharSet.Auto)]
  671. private static extern bool _WriteAnalogFilterGain1_M3(byte nCOMPort, byte nNodeID, ushort nAnalogFilterGain);
  672. // Read analog filter gain
  673. [DllImport(DLL_FILENAME, EntryPoint = "ReadAnalogFilterGain2_M3", CharSet = CharSet.Auto)]
  674. private static extern bool _ReadAnalogFilterGain2_M3(byte nCOMPort, byte nNodeID, ref ushort nAnalogFilterGain);
  675. // Write analog filter gain
  676. [DllImport(DLL_FILENAME, EntryPoint = "WriteAnalogFilterGain2_M3", CharSet = CharSet.Auto)]
  677. private static extern bool _WriteAnalogFilterGain2_M3(byte nCOMPort, byte nNodeID, ushort nAnalogFilterGain);
  678. // Write broadcast command
  679. [DllImport(DLL_FILENAME, EntryPoint = "WriteBroadcastCommand", CharSet = CharSet.Auto)]
  680. private static extern bool _WriteBroadcastCommand(byte nCOMPort, byte nNodeIDCount, [MarshalAs(UnmanagedType.LPArray, SizeConst = 32)] byte[] aNodeIDArr, byte nFunctionCode);
  681. // Execute multi-axes linear interpolation move
  682. [DllImport(DLL_FILENAME, EntryPoint = "ExecuteLinearInterpolationMove", CharSet = CharSet.Auto)]
  683. private static extern bool _ExecuteLinearInterpolationMove(byte nCOMPort, byte nNodeIDCount, [MarshalAs(UnmanagedType.LPArray, SizeConst = 4)] byte[] aNodeIDArr, [MarshalAs(UnmanagedType.LPArray, SizeConst = 4)] int[] aPosArr, uint nMaxLineSpeed, uint nAccelTimeInMs, bool bRelMove, bool bValidParamLimit);
  684. #endregion
  685. #region Public Methods
  686. private static CSCallback m_DataSendCallback;
  687. private static CSCallback m_DataReceivedCallback;
  688. public delegate void OnDataSendOrReceivedEventHandler(EventArgs e);
  689. public event OnDataSendOrReceivedEventHandler DataSend;
  690. public event OnDataSendOrReceivedEventHandler DataReceived;
  691. public void DataSendCallbackFunction()
  692. {
  693. if (DataSend != null)
  694. {
  695. EventArgs e = new EventArgs();
  696. DataSend(e);
  697. }
  698. }
  699. public void DataReceivedCallbackFunction()
  700. {
  701. if (DataReceived != null)
  702. {
  703. EventArgs e = new EventArgs();
  704. DataReceived(e);
  705. }
  706. }
  707. public ModbusRTU()
  708. {
  709. m_DataSendCallback = DataSendCallbackFunction;
  710. _OnDataSend(m_DataSendCallback);
  711. m_DataReceivedCallback = DataReceivedCallbackFunction;
  712. _OnDataReceive(m_DataReceivedCallback);
  713. }
  714. public bool IsOpen()
  715. {
  716. return _IsOpen(m_COMPort);
  717. }
  718. public bool Open(byte nCOMPort, int baudRate, bool bigEndian = true)
  719. {
  720. m_COMPort = nCOMPort;
  721. return _Open(m_COMPort, baudRate, bigEndian);
  722. }
  723. public bool Close()
  724. {
  725. return _Close(m_COMPort);
  726. }
  727. ~ModbusRTU()
  728. {
  729. Close();
  730. }
  731. // Set when send data, trigger Send event or not
  732. public void SetEndianType(bool bBigEndian)
  733. {
  734. _SetEndianType(m_COMPort, bBigEndian);
  735. }
  736. // Set when received data, trigger Send event or not
  737. public bool IsBigEndian()
  738. {
  739. return _IsBigEndian(m_COMPort);
  740. }
  741. // Set when received data, trigger Send event or not
  742. public uint GetExecuteTimeOut()
  743. {
  744. return _GetExecuteTimeOut(m_COMPort);
  745. }
  746. // Set when send data, trigger Send event or not
  747. public void SetExecuteTimeOut(uint nExecuteTimeOut)
  748. {
  749. _SetExecuteTimeOut(m_COMPort, nExecuteTimeOut);
  750. }
  751. // Set it will trigger send event or not when sending command
  752. public void SetTriggerSendEvent(bool bTriggerSendEvent)
  753. {
  754. _SetTriggerSendEvent(bTriggerSendEvent);
  755. }
  756. // Set it will trigger received event or not when receive data
  757. public void SetTriggerReceiveEvent(bool bTriggerReceiveEvent)
  758. {
  759. _SetTriggerReceiveEvent(bTriggerReceiveEvent);
  760. }
  761. // Clear send buffer
  762. public void ClearSendBuffer(byte nCOMPort)
  763. {
  764. _ClearSendBuffer(nCOMPort);
  765. }
  766. // Clear received buffer
  767. public void ClearReceivedBuffer(byte nCOMPort)
  768. {
  769. _ClearReceivedBuffer(nCOMPort);
  770. }
  771. // Clear send and received Buffer
  772. public void ClearBuffer(byte nCOMPort)
  773. {
  774. _ClearBuffer(nCOMPort);
  775. }
  776. // Get last error information, includes code and description
  777. public void GetLastErrorInfo(ref ErrorInfo errorInfo)
  778. {
  779. _GetLastErrorInfo(ref errorInfo);
  780. }
  781. // Get the last command that send
  782. public void GetLastCommandSent(ref List<byte> commandList)
  783. {
  784. IntPtr ptrCommandStu = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(StructCommand)));
  785. bool ret = _GetLastCommandSent(m_COMPort, ptrCommandStu);
  786. StructCommand commandStu = (StructCommand)Marshal.PtrToStructure((IntPtr)((UInt32)ptrCommandStu), typeof(StructCommand));
  787. for (int i = 0; i < commandStu.Count; i++)
  788. {
  789. commandList.Add(commandStu.Values[i]);
  790. }
  791. Marshal.FreeHGlobal(ptrCommandStu);
  792. }
  793. // Get the last command that received
  794. public void GetLastCommandReceived(ref List<byte> commandList)
  795. {
  796. IntPtr ptrCommandStu = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(StructCommand)));
  797. bool ret = _GetLastCommandReceived(m_COMPort, ptrCommandStu);
  798. StructCommand commandStu = (StructCommand)Marshal.PtrToStructure((IntPtr)((UInt32)ptrCommandStu), typeof(StructCommand));
  799. for (int i = 0; i < commandStu.Count; i++)
  800. {
  801. commandList.Add(commandStu.Values[i]);
  802. }
  803. Marshal.FreeHGlobal(ptrCommandStu);
  804. }
  805. // Read single holding register from the drive
  806. public bool ReadSingleHoldingRegister(byte nNodeID, int registerNo, ref int value)
  807. {
  808. return _ReadSingleHoldingRegister(m_COMPort, nNodeID, registerNo, ref value);
  809. }
  810. // Write single holding register value to the drive
  811. public bool WriteSingleHoldingRegister(byte nNodeID, int registerNo, int value)
  812. {
  813. return _WriteSingleHoldingRegister(m_COMPort, nNodeID, registerNo, value);
  814. }
  815. // Read multiple holding register from the drive
  816. public bool ReadMultiHoldingRegisters(byte nNodeID, int registerNo, int count, ref List<int> valueList)
  817. {
  818. IntPtr ptrHoldingRegisterStu = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(StructRegisterValue)));
  819. bool ret = _ReadMultiHoldingRegisters(m_COMPort, nNodeID, registerNo, count, ptrHoldingRegisterStu);
  820. StructRegisterValue holdingRegisterStu = (StructRegisterValue)Marshal.PtrToStructure((IntPtr)((UInt32)ptrHoldingRegisterStu), typeof(StructRegisterValue));
  821. for (int i = 0; i < holdingRegisterStu.Count; i++)
  822. {
  823. valueList.Add(holdingRegisterStu.Values[i]);
  824. }
  825. Marshal.FreeHGlobal(ptrHoldingRegisterStu);
  826. return ret;
  827. }
  828. // Write multiple holding register values to the drive
  829. public bool WriteMultiHoldingRegisters(byte nNodeID, int registerNo, int count, List<int> lstValue)
  830. {
  831. int[] valueList = lstValue.ToArray();
  832. bool ret = _WriteMultiHoldingRegisters(m_COMPort, nNodeID, registerNo, count, valueList);
  833. return ret;
  834. }
  835. // Read 16-bit int data from the drive
  836. public bool ReadDataInt16(byte nNodeID, int nRegisterNo, ref short nValue)
  837. {
  838. return _ReadDataInt16(m_COMPort, nNodeID, nRegisterNo, ref nValue);
  839. }
  840. // Write 16-bit int data to the drive
  841. public bool WriteDataInt16(byte nNodeID, int nRegisterNo, short nValue)
  842. {
  843. return _WriteDataInt16(m_COMPort, nNodeID, nRegisterNo, nValue);
  844. }
  845. // Read 16-bit unsighed int data from the drive
  846. public bool ReadDataUInt16(byte nNodeID, int nRegisterNo, ref ushort nValue)
  847. {
  848. return _ReadDataUInt16(m_COMPort, nNodeID, nRegisterNo, ref nValue);
  849. }
  850. // Write 16-bit unsigned int data to the drive
  851. public bool WriteDataUInt16(byte nNodeID, int nRegisterNo, ushort nValue)
  852. {
  853. return _WriteDataUInt16(m_COMPort, nNodeID, nRegisterNo, nValue);
  854. }
  855. // Read 32-bit int data from the drive
  856. public bool ReadDataInt32(byte nNodeID, int nRegisterNo, ref int nValue)
  857. {
  858. return _ReadDataInt32(m_COMPort, nNodeID, nRegisterNo, ref nValue);
  859. }
  860. // Write 32-bit int data to the drive
  861. public bool WriteDataInt32(byte nNodeID, int nRegisterNo, int nValue)
  862. {
  863. return _WriteDataInt32(m_COMPort, nNodeID, nRegisterNo, nValue);
  864. }
  865. // Read 32-bit unsighed int data from the drive
  866. public bool ReadDataUInt32(byte nNodeID, int nRegisterNo, ref uint nValue)
  867. {
  868. return _ReadDataUInt32(m_COMPort, nNodeID, nRegisterNo, ref nValue);
  869. }
  870. // Write 32-bit unsigned int data to the drive
  871. public bool WriteDataUInt32(byte nNodeID, int nRegisterNo, uint nValue)
  872. {
  873. return _WriteDataUInt32(m_COMPort, nNodeID, nRegisterNo, nValue);
  874. }
  875. // Execute command with opcode
  876. public bool ExecuteCommandWithOpcode(byte nNodeID, SCLCommandEncodingTable commandCode, int p1 = 0, int p2 = 0, int p3 = 0, int p4 = 0, int p5 = 0)
  877. {
  878. return _ExecuteCommandWithOpcode(m_COMPort, nNodeID, (int)commandCode, p1, p2, p3, p4, p5);
  879. }
  880. // Write multiple holding register values to the drive
  881. public bool ExecuteSCLCommand(byte nNodeID, int registerNo, byte[] command, ref string strResponse)
  882. {
  883. IntPtr strIntPtr = IntPtr.Zero;
  884. bool ret = _ExecuteSCLCommand(m_COMPort, nNodeID, registerNo, command, ref strIntPtr);
  885. strResponse = Marshal.PtrToStringAnsi(strIntPtr);
  886. return ret;
  887. }
  888. public bool ExecuteSCLCommand(byte nNodeID, int registerNo, string command, ref string strResponse)
  889. {
  890. byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(command);
  891. return ExecuteSCLCommand(nNodeID, registerNo, buf, ref strResponse);
  892. }
  893. // Set P2P profile arguments
  894. public bool SetP2PProfile(byte nNodeID, double? dVelocity, double? dAccel, double? dDecel)
  895. {
  896. IntPtr ptrAccel = IntPtr.Zero;
  897. if (dAccel != null)
  898. {
  899. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  900. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  901. }
  902. IntPtr ptrDecel = IntPtr.Zero;
  903. if (dDecel != null)
  904. {
  905. ptrDecel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  906. Marshal.StructureToPtr(dDecel.Value, ptrDecel, true);
  907. }
  908. IntPtr ptrVelocity = IntPtr.Zero;
  909. if (dVelocity != null)
  910. {
  911. ptrVelocity = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  912. Marshal.StructureToPtr(dVelocity.Value, ptrVelocity, true);
  913. }
  914. bool ret = _SetP2PProfile(m_COMPort, nNodeID, ptrVelocity, ptrAccel, ptrDecel);
  915. Marshal.FreeHGlobal(ptrAccel);
  916. Marshal.FreeHGlobal(ptrDecel);
  917. Marshal.FreeHGlobal(ptrVelocity);
  918. return ret;
  919. }
  920. // Set Jog profile arguments
  921. public bool SetJogProfile(byte nNodeID, double? dVelocity, double? dAccel, double? dDecel)
  922. {
  923. IntPtr ptrAccel = IntPtr.Zero;
  924. if (dAccel != null)
  925. {
  926. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  927. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  928. }
  929. IntPtr ptrDecel = IntPtr.Zero;
  930. if (dDecel != null)
  931. {
  932. ptrDecel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  933. Marshal.StructureToPtr(dDecel.Value, ptrDecel, true);
  934. }
  935. IntPtr ptrVelocity = IntPtr.Zero;
  936. if (dVelocity != null)
  937. {
  938. ptrVelocity = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  939. Marshal.StructureToPtr(dVelocity.Value, ptrVelocity, true);
  940. }
  941. bool ret = _SetJogProfile(m_COMPort, nNodeID, ptrVelocity, ptrAccel, ptrDecel);
  942. Marshal.FreeHGlobal(ptrAccel);
  943. Marshal.FreeHGlobal(ptrDecel);
  944. Marshal.FreeHGlobal(ptrVelocity);
  945. return ret;
  946. }
  947. // Set the drive enabled or disabled
  948. public bool DriveEnable(byte nNodeID, bool bEnable)
  949. {
  950. return _DriveEnable(m_COMPort, nNodeID, bEnable);
  951. }
  952. // Reset drive's dlarm
  953. public bool AlarmReset(byte nNodeID)
  954. {
  955. return _AlarmReset(m_COMPort, nNodeID);
  956. }
  957. // Launch feed to position move
  958. public bool FeedtoPosition(byte nNodeID, int? nPosition = null)
  959. {
  960. IntPtr ptrPosition = IntPtr.Zero;
  961. if (nPosition.HasValue)
  962. {
  963. ptrPosition = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  964. Marshal.StructureToPtr(nPosition.Value, ptrPosition, true);
  965. }
  966. bool ret = _FeedtoPosition(m_COMPort, nNodeID, ptrPosition);
  967. Marshal.FreeHGlobal(ptrPosition);
  968. return ret;
  969. }
  970. // Launch feed to length move
  971. public bool FeedtoLength(byte nNodeID, int? nDistance = null)
  972. {
  973. IntPtr ptrPosition = IntPtr.Zero;
  974. if (nDistance.HasValue)
  975. {
  976. ptrPosition = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  977. Marshal.StructureToPtr(nDistance.Value, ptrPosition, true);
  978. }
  979. bool ret = _FeedtoLength(m_COMPort, nNodeID, ptrPosition);
  980. Marshal.FreeHGlobal(ptrPosition);
  981. return ret;
  982. }
  983. // Launch absolute move
  984. public bool AbsMove(byte nNodeID, int nDistance, double? dVelocity, double? dAccel, double? dDecel)
  985. {
  986. IntPtr ptrAccel = IntPtr.Zero;
  987. if (dAccel != null)
  988. {
  989. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  990. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  991. }
  992. IntPtr ptrDecel = IntPtr.Zero;
  993. if (dDecel != null)
  994. {
  995. ptrDecel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  996. Marshal.StructureToPtr(dDecel.Value, ptrDecel, true);
  997. }
  998. IntPtr ptrVelocity = IntPtr.Zero;
  999. if (dVelocity != null)
  1000. {
  1001. ptrVelocity = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1002. Marshal.StructureToPtr(dVelocity.Value, ptrVelocity, true);
  1003. }
  1004. bool ret = _AbsMove(m_COMPort, nNodeID, nDistance, ptrVelocity, ptrAccel, ptrDecel);
  1005. Marshal.FreeHGlobal(ptrAccel);
  1006. Marshal.FreeHGlobal(ptrDecel);
  1007. Marshal.FreeHGlobal(ptrVelocity);
  1008. return ret;
  1009. }
  1010. // Launch relative move
  1011. public bool RelMove(byte nNodeID, int nDistance, double? dVelocity, double? dAccel, double? dDecel)
  1012. {
  1013. IntPtr ptrAccel = IntPtr.Zero;
  1014. if (dAccel != null)
  1015. {
  1016. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1017. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  1018. }
  1019. IntPtr ptrDecel = IntPtr.Zero;
  1020. if (dDecel != null)
  1021. {
  1022. ptrDecel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1023. Marshal.StructureToPtr(dDecel.Value, ptrDecel, true);
  1024. }
  1025. IntPtr ptrVelocity = IntPtr.Zero;
  1026. if (dVelocity != null)
  1027. {
  1028. ptrVelocity = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1029. Marshal.StructureToPtr(dVelocity.Value, ptrVelocity, true);
  1030. }
  1031. bool ret = _RelMove(m_COMPort, nNodeID, nDistance, ptrVelocity, ptrAccel, ptrDecel);
  1032. Marshal.FreeHGlobal(ptrAccel);
  1033. Marshal.FreeHGlobal(ptrDecel);
  1034. Marshal.FreeHGlobal(ptrVelocity);
  1035. return ret;
  1036. }
  1037. // Launch feed to sensor move
  1038. public bool FeedtoSensor(byte nNodeID, byte nInputSensor, char chInputStatus)
  1039. {
  1040. return _FeedtoSensor(m_COMPort, nNodeID, nInputSensor, chInputStatus);
  1041. }
  1042. // Lanuch feed to sensor move with safety distance
  1043. public bool FeedtoSensorwithSafetyDistance(byte nNodeID, byte nInputSensor, char chInputStatus)
  1044. {
  1045. return _FeedtoSensorwithSafetyDistance(m_COMPort, nNodeID, nInputSensor, chInputStatus);
  1046. }
  1047. // Launch feed to double sensor move with mask distance
  1048. public bool FeedtoSensorwithMaskDistance(byte nNodeID, byte nInputSensor, char chInputStatus)
  1049. {
  1050. return _FeedtoSensorwithMaskDistance(m_COMPort, nNodeID, nInputSensor, chInputStatus);
  1051. }
  1052. // Launch Point to Point Move and set output
  1053. public bool FeedandSetOutput(byte nNodeID, byte nOutput, char chOutputStatus)
  1054. {
  1055. return _FeedandSetOutput(m_COMPort, nNodeID, nOutput, chOutputStatus);
  1056. }
  1057. // Launch feed to double sensor move
  1058. public bool FeedtoDoubleSensor(byte nNodeID, byte nInput1, char chInputStatus1, byte nInput2, char chInputStatus2)
  1059. {
  1060. return _FeedtoDoubleSensor(m_COMPort, nNodeID, nInput1, chInputStatus1, nInput2, chInputStatus2);
  1061. }
  1062. // Launch follow encoder move
  1063. public bool FollowEncoder(byte nNodeID, byte nInputSensor, char chInputStatus)
  1064. {
  1065. return _FollowEncoder(m_COMPort, nNodeID, nInputSensor, chInputStatus);
  1066. }
  1067. // Commence Jogging
  1068. public bool StartJogging(byte nNodeID)
  1069. {
  1070. return _StartJogging(m_COMPort, nNodeID);
  1071. }
  1072. // Stop Jogging
  1073. public bool StopJogging(byte nNodeID)
  1074. {
  1075. return _StopJogging(m_COMPort, nNodeID);
  1076. }
  1077. // Set encoder function to the stepper drives with encoder feedback
  1078. public bool SetEncoderFunction(byte nNodeID, byte nFunc)
  1079. {
  1080. return _SetEncoderFunction(m_COMPort, nNodeID, nFunc);
  1081. }
  1082. // Set encoder position
  1083. public bool SetEncoderPosition(byte nNodeID, int nPosition)
  1084. {
  1085. return _SetEncoderPosition(m_COMPort, nNodeID, nPosition);
  1086. }
  1087. // Jog disable
  1088. public bool JogDisable(byte nNodeID)
  1089. {
  1090. return _JogDisable(m_COMPort, nNodeID);
  1091. }
  1092. // Jog enable
  1093. public bool JogEnable(byte nNodeID)
  1094. {
  1095. return _JogEnable(m_COMPort, nNodeID);
  1096. }
  1097. // Launch seek home move
  1098. public bool SeekHome(byte nNodeID, byte nInputSensor, char chInputStatus)
  1099. {
  1100. return _SeekHome(m_COMPort, nNodeID, nInputSensor, chInputStatus);
  1101. }
  1102. // Set position
  1103. public bool SetPosition(byte nNodeID, int nPosition)
  1104. {
  1105. return _SetPosition(m_COMPort, nNodeID, nPosition);
  1106. }
  1107. // Set filter input
  1108. public bool SetFilterInput(byte nNodeID, byte nInputSensor, int nFilterTime)
  1109. {
  1110. return _SetFilterInput(m_COMPort, nNodeID, nInputSensor, nFilterTime);
  1111. }
  1112. // Analog deadband
  1113. public bool WriteAnalogDeadband(byte nNodeID, byte nDeadband)
  1114. {
  1115. return _WriteAnalogDeadband(m_COMPort, nNodeID, nDeadband);
  1116. }
  1117. // Set output of the drive
  1118. public bool SetOutput(byte nNodeID, byte nOutput, char nCondition)
  1119. {
  1120. return _SetOutput(m_COMPort, nNodeID, nOutput, nCondition);
  1121. }
  1122. // Wait for input
  1123. public bool WriteWaitforInput(byte nNodeID, byte nInputSensor, char nCondition)
  1124. {
  1125. return _WriteWaitforInput(m_COMPort, nNodeID, nInputSensor, nCondition);
  1126. }
  1127. // Queue Load and Execute
  1128. public bool QueueLoadAndExecute(byte nNodeID, byte nSegment)
  1129. {
  1130. return _QueueLoadAndExecute(m_COMPort, nNodeID, nSegment);
  1131. }
  1132. // Wait time
  1133. public bool WriteWaitTime(byte nNodeID, ushort nTime)
  1134. {
  1135. return _WriteWaitTime(m_COMPort, nNodeID, nTime);
  1136. }
  1137. // Stop and kill current move
  1138. public bool StopAndKill(byte nNodeID)
  1139. {
  1140. return _StopAndKill(m_COMPort, nNodeID);
  1141. }
  1142. // Stop and kill current move with normal deceleration
  1143. public bool StopAndKillwithNormalDecel(byte nNodeID)
  1144. {
  1145. return _StopAndKillwithNormalDecel(m_COMPort, nNodeID);
  1146. }
  1147. // Set P2P profile arguments
  1148. public bool SetP2PProfile_M3(byte nNodeID, double? dVelocity, double? dAccel, double? dDecel)
  1149. {
  1150. IntPtr ptrAccel = IntPtr.Zero;
  1151. if (dAccel != null)
  1152. {
  1153. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1154. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  1155. }
  1156. IntPtr ptrDecel = IntPtr.Zero;
  1157. if (dDecel != null)
  1158. {
  1159. ptrDecel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1160. Marshal.StructureToPtr(dDecel.Value, ptrDecel, true);
  1161. }
  1162. IntPtr ptrVelocity = IntPtr.Zero;
  1163. if (dVelocity != null)
  1164. {
  1165. ptrVelocity = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1166. Marshal.StructureToPtr(dVelocity.Value, ptrVelocity, true);
  1167. }
  1168. bool ret = _SetP2PProfile_M3(m_COMPort, nNodeID, ptrVelocity, ptrAccel, ptrDecel);
  1169. Marshal.FreeHGlobal(ptrAccel);
  1170. Marshal.FreeHGlobal(ptrDecel);
  1171. Marshal.FreeHGlobal(ptrVelocity);
  1172. return ret;
  1173. }
  1174. // Set Jog profile arguments
  1175. public bool SetJogProfile_M3(byte nNodeID, double? dVelocity, double? dAccel, double? dDecel)
  1176. {
  1177. IntPtr ptrAccel = IntPtr.Zero;
  1178. if (dAccel != null)
  1179. {
  1180. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1181. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  1182. }
  1183. IntPtr ptrDecel = IntPtr.Zero;
  1184. if (dDecel != null)
  1185. {
  1186. ptrDecel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1187. Marshal.StructureToPtr(dDecel.Value, ptrDecel, true);
  1188. }
  1189. IntPtr ptrVelocity = IntPtr.Zero;
  1190. if (dVelocity != null)
  1191. {
  1192. ptrVelocity = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1193. Marshal.StructureToPtr(dVelocity.Value, ptrVelocity, true);
  1194. }
  1195. bool ret = _SetJogProfile_M3(m_COMPort, nNodeID, ptrVelocity, ptrAccel, ptrDecel);
  1196. Marshal.FreeHGlobal(ptrAccel);
  1197. Marshal.FreeHGlobal(ptrDecel);
  1198. Marshal.FreeHGlobal(ptrVelocity);
  1199. return ret;
  1200. }
  1201. // Set the drive enabled or disabled
  1202. public bool DriveEnable_M3(byte nNodeID, bool bEnable)
  1203. {
  1204. return _DriveEnable_M3(m_COMPort, nNodeID, bEnable);
  1205. }
  1206. // Launch feed to position move
  1207. public bool FeedtoPosition_M3(byte nNodeID, int? nPosition = null)
  1208. {
  1209. IntPtr ptrPosition = IntPtr.Zero;
  1210. if (nPosition.HasValue)
  1211. {
  1212. ptrPosition = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1213. Marshal.StructureToPtr(nPosition.Value, ptrPosition, true);
  1214. }
  1215. bool ret = _FeedtoPosition_M3(m_COMPort, nNodeID, ptrPosition);
  1216. Marshal.FreeHGlobal(ptrPosition);
  1217. return ret;
  1218. }
  1219. // Launch feed to length move
  1220. public bool FeedtoLength_M3(byte nNodeID, int? nDistance = null)
  1221. {
  1222. IntPtr ptrPosition = IntPtr.Zero;
  1223. if (nDistance.HasValue)
  1224. {
  1225. ptrPosition = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1226. Marshal.StructureToPtr(nDistance.Value, ptrPosition, true);
  1227. }
  1228. bool ret = _FeedtoLength_M3(m_COMPort, nNodeID, ptrPosition);
  1229. Marshal.FreeHGlobal(ptrPosition);
  1230. return ret;
  1231. }
  1232. // Reset drive's dlarm
  1233. public bool AlarmReset_M3(byte nNodeID)
  1234. {
  1235. return _AlarmReset_M3(m_COMPort, nNodeID);
  1236. }
  1237. // Launch absolute move
  1238. public bool AbsMove_M3(byte nNodeID, int nDistance, double? dVelocity, double? dAccel, double? dDecel)
  1239. {
  1240. IntPtr ptrAccel = IntPtr.Zero;
  1241. if (dAccel != null)
  1242. {
  1243. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1244. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  1245. }
  1246. IntPtr ptrDecel = IntPtr.Zero;
  1247. if (dDecel != null)
  1248. {
  1249. ptrDecel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1250. Marshal.StructureToPtr(dDecel.Value, ptrDecel, true);
  1251. }
  1252. IntPtr ptrVelocity = IntPtr.Zero;
  1253. if (dVelocity != null)
  1254. {
  1255. ptrVelocity = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1256. Marshal.StructureToPtr(dVelocity.Value, ptrVelocity, true);
  1257. }
  1258. bool ret = _AbsMove_M3(m_COMPort, nNodeID, nDistance, ptrVelocity, ptrAccel, ptrDecel);
  1259. Marshal.FreeHGlobal(ptrAccel);
  1260. Marshal.FreeHGlobal(ptrDecel);
  1261. Marshal.FreeHGlobal(ptrVelocity);
  1262. return ret;
  1263. }
  1264. // Launch relative move
  1265. public bool RelMove_M3(byte nNodeID, int nDistance, double? dVelocity, double? dAccel, double? dDecel)
  1266. {
  1267. IntPtr ptrAccel = IntPtr.Zero;
  1268. if (dAccel != null)
  1269. {
  1270. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1271. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  1272. }
  1273. IntPtr ptrDecel = IntPtr.Zero;
  1274. if (dDecel != null)
  1275. {
  1276. ptrDecel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1277. Marshal.StructureToPtr(dDecel.Value, ptrDecel, true);
  1278. }
  1279. IntPtr ptrVelocity = IntPtr.Zero;
  1280. if (dVelocity != null)
  1281. {
  1282. ptrVelocity = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1283. Marshal.StructureToPtr(dVelocity.Value, ptrVelocity, true);
  1284. }
  1285. bool ret = _RelMove_M3(m_COMPort, nNodeID, nDistance, ptrVelocity, ptrAccel, ptrDecel);
  1286. Marshal.FreeHGlobal(ptrAccel);
  1287. Marshal.FreeHGlobal(ptrDecel);
  1288. Marshal.FreeHGlobal(ptrVelocity);
  1289. return ret;
  1290. }
  1291. // Set Home profile arguments
  1292. public bool SetHomeProfile(byte nNodeID, double? dVelocity1, double? dVelocity2, double? dAccel, int? nHomingOffset = null)
  1293. {
  1294. IntPtr ptrVelocity1 = IntPtr.Zero;
  1295. if (dVelocity1 != null)
  1296. {
  1297. ptrVelocity1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1298. Marshal.StructureToPtr(dVelocity1.Value, ptrVelocity1, true);
  1299. }
  1300. IntPtr ptrVelocity2 = IntPtr.Zero;
  1301. if (dVelocity2 != null)
  1302. {
  1303. ptrVelocity2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1304. Marshal.StructureToPtr(dVelocity2.Value, ptrVelocity2, true);
  1305. }
  1306. IntPtr ptrAccel = IntPtr.Zero;
  1307. if (dAccel != null)
  1308. {
  1309. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1310. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  1311. }
  1312. IntPtr ptrHomingOffset = IntPtr.Zero;
  1313. if (nHomingOffset.HasValue)
  1314. {
  1315. ptrHomingOffset = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1316. Marshal.StructureToPtr(nHomingOffset.Value, ptrHomingOffset, true);
  1317. }
  1318. bool ret = _SetHomeProfile(m_COMPort, nNodeID, ptrVelocity1, ptrVelocity2, ptrAccel, ptrHomingOffset);
  1319. Marshal.FreeHGlobal(ptrVelocity1);
  1320. Marshal.FreeHGlobal(ptrVelocity2);
  1321. Marshal.FreeHGlobal(ptrAccel);
  1322. Marshal.FreeHGlobal(ptrHomingOffset);
  1323. return ret;
  1324. }
  1325. // Set feed home method
  1326. public bool SetHomeMethod(byte nNodeID, sbyte nHomeMethod)
  1327. {
  1328. return _SetHomeMethod(m_COMPort, nNodeID, nHomeMethod);
  1329. }
  1330. // Launch feed home move
  1331. public bool FeedHome(byte nNodeID, sbyte nHomeMethod, double? dVelocity1 = null, double? dVelocity2 = null, double? dAccel = null, int? nHomingOffset = null)
  1332. {
  1333. IntPtr ptrVelocity1 = IntPtr.Zero;
  1334. if (dVelocity1 != null)
  1335. {
  1336. ptrVelocity1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1337. Marshal.StructureToPtr(dVelocity1.Value, ptrVelocity1, true);
  1338. }
  1339. IntPtr ptrVelocity2 = IntPtr.Zero;
  1340. if (dVelocity2 != null)
  1341. {
  1342. ptrVelocity2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1343. Marshal.StructureToPtr(dVelocity2.Value, ptrVelocity2, true);
  1344. }
  1345. IntPtr ptrAccel = IntPtr.Zero;
  1346. if (dAccel != null)
  1347. {
  1348. ptrAccel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1349. Marshal.StructureToPtr(dAccel.Value, ptrAccel, true);
  1350. }
  1351. IntPtr ptrHomingOffset = IntPtr.Zero;
  1352. if (nHomingOffset.HasValue)
  1353. {
  1354. ptrHomingOffset = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)));
  1355. Marshal.StructureToPtr(nHomingOffset.Value, ptrHomingOffset, true);
  1356. }
  1357. bool ret = _FeedHome(m_COMPort, nNodeID, nHomeMethod, ptrVelocity1, ptrVelocity2, ptrAccel, ptrHomingOffset);
  1358. Marshal.FreeHGlobal(ptrVelocity1);
  1359. Marshal.FreeHGlobal(ptrVelocity2);
  1360. Marshal.FreeHGlobal(ptrAccel);
  1361. Marshal.FreeHGlobal(ptrHomingOffset);
  1362. return ret;
  1363. }
  1364. // Read alarm code
  1365. public bool ReadAlarmCode(byte nNodeID, ref uint nAlarmCode)
  1366. {
  1367. return _ReadAlarmCode(m_COMPort, nNodeID, ref nAlarmCode);
  1368. }
  1369. // Read status code
  1370. public bool ReadStatusCode(byte nNodeID, ref uint nStatusCode)
  1371. {
  1372. return _ReadStatusCode(m_COMPort, nNodeID, ref nStatusCode);
  1373. }
  1374. // Read immediate expanded inputs
  1375. public bool ReadImmediateExpandedInputs(byte nNodeID, ref ushort nInputsStatus)
  1376. {
  1377. return _ReadImmediateExpandedInputs(m_COMPort, nNodeID, ref nInputsStatus);
  1378. }
  1379. // Read driver board inputs
  1380. public bool ReadDriverBoardInputs(byte nNodeID, ref ushort nInputsStatus)
  1381. {
  1382. return _ReadDriverBoardInputs(m_COMPort, nNodeID, ref nInputsStatus);
  1383. }
  1384. // Read encoder position
  1385. public bool ReadEncoderPosition(byte nNodeID, ref int nEncoderPosition)
  1386. {
  1387. return _ReadEncoderPosition(m_COMPort, nNodeID, ref nEncoderPosition);
  1388. }
  1389. // Read immediate absolute position
  1390. public bool ReadImmediateAbsolutePosition(byte nNodeID, ref int nImmediateAbsolutePosition)
  1391. {
  1392. return _ReadImmediateAbsolutePosition(m_COMPort, nNodeID, ref nImmediateAbsolutePosition);
  1393. }
  1394. // Read immediate actual velocity
  1395. public bool ReadImmediateActualVelocity(byte nNodeID, ref double dImmediateActualVelocity)
  1396. {
  1397. return _ReadImmediateActualVelocity(m_COMPort, nNodeID, ref dImmediateActualVelocity);
  1398. }
  1399. // Read immediate target velocity
  1400. public bool ReadImmediateTargetVelocity(byte nNodeID, ref double dImmediateTargetVelocity)
  1401. {
  1402. return _ReadImmediateTargetVelocity(m_COMPort, nNodeID, ref dImmediateTargetVelocity);
  1403. }
  1404. // Read immediate drive temperature
  1405. public bool ReadImmediateDriveTemperature(byte nNodeID, ref double dImmediateDriveTemperature)
  1406. {
  1407. return _ReadImmediateDriveTemperature(m_COMPort, nNodeID, ref dImmediateDriveTemperature);
  1408. }
  1409. // Read immediate bus voltage
  1410. public bool ReadImmediateBusVoltage(byte nNodeID, ref double dImmediateBusVoltage)
  1411. {
  1412. return _ReadImmediateBusVoltage(m_COMPort, nNodeID, ref dImmediateBusVoltage);
  1413. }
  1414. // Read immediate position error
  1415. public bool ReadImmediatePositionError(byte nNodeID, ref int nImmediatePositionError)
  1416. {
  1417. return _ReadImmediatePositionError(m_COMPort, nNodeID, ref nImmediatePositionError);
  1418. }
  1419. // Read immediate analog input value
  1420. public bool ReadImmediateAnalogInputValue(byte nNodeID, ref short nImmediateAnalogInputValue)
  1421. {
  1422. return _ReadImmediateAnalogInputValue(m_COMPort, nNodeID, ref nImmediateAnalogInputValue);
  1423. }
  1424. // Read immediate analog input1 Value
  1425. public bool ReadImmediateAnalogInput1Value(byte nNodeID, ref short nImmediateAnalogInputValue)
  1426. {
  1427. return _ReadImmediateAnalogInput1Value(m_COMPort, nNodeID, ref nImmediateAnalogInputValue);
  1428. }
  1429. // Read immediate analog input2 Value
  1430. public bool ReadImmediateAnalogInput2Value(byte nNodeID, ref short nImmediateAnalogInputValue)
  1431. {
  1432. return _ReadImmediateAnalogInput2Value(m_COMPort, nNodeID, ref nImmediateAnalogInputValue);
  1433. }
  1434. // Read Q program line number
  1435. public bool ReadQProgramLineNumber(byte nNodeID, ref ushort nQProgramLineNumber)
  1436. {
  1437. return _ReadQProgramLineNumber(m_COMPort, nNodeID, ref nQProgramLineNumber);
  1438. }
  1439. // Read immediate current command
  1440. public bool ReadImmediateCurrentCommand(byte nNodeID, ref short nImmediateCurrentCommand)
  1441. {
  1442. return _ReadImmediateCurrentCommand(m_COMPort, nNodeID, ref nImmediateCurrentCommand);
  1443. }
  1444. // Read relative distance
  1445. public bool ReadRelativeDistance(byte nNodeID, ref int nRelativeDistance)
  1446. {
  1447. return _ReadRelativeDistance(m_COMPort, nNodeID, ref nRelativeDistance);
  1448. }
  1449. // Read sensor position
  1450. public bool ReadSensorPosition(byte nNodeID, ref int nSensorPosition)
  1451. {
  1452. return _ReadSensorPosition(m_COMPort, nNodeID, ref nSensorPosition);
  1453. }
  1454. // Read condition code
  1455. public bool ReadConditionCode(byte nNodeID, ref ushort nConditionCode)
  1456. {
  1457. return _ReadConditionCode(m_COMPort, nNodeID, ref nConditionCode);
  1458. }
  1459. // Read command mode
  1460. public bool ReadCommandMode(byte nNodeID, ref ushort nCommandMode)
  1461. {
  1462. return _ReadCommandMode(m_COMPort, nNodeID, ref nCommandMode);
  1463. }
  1464. // Read distance or position
  1465. public bool ReadDistanceOrPosition(byte nNodeID, ref int nDistanceOrPosition)
  1466. {
  1467. return _ReadDistanceOrPosition(m_COMPort, nNodeID, ref nDistanceOrPosition);
  1468. }
  1469. // Write distance or position
  1470. public bool WriteDistanceOrPosition(byte nNodeID, int nDistanceOrPosition)
  1471. {
  1472. return _WriteDistanceOrPosition(m_COMPort, nNodeID, nDistanceOrPosition);
  1473. }
  1474. // Read change distance
  1475. public bool ReadChangeDistance(byte nNodeID, ref int nChangeDistance)
  1476. {
  1477. return _ReadChangeDistance(m_COMPort, nNodeID, ref nChangeDistance);
  1478. }
  1479. // Write change distance
  1480. public bool WriteChangeDistance(byte nNodeID, int nChangeDistance)
  1481. {
  1482. return _WriteChangeDistance(m_COMPort, nNodeID, nChangeDistance);
  1483. }
  1484. // Read change velocity
  1485. public bool ReadChangeVelocity(byte nNodeID, ref double dChangeVelocity)
  1486. {
  1487. return _ReadChangeVelocity(m_COMPort, nNodeID, ref dChangeVelocity);
  1488. }
  1489. // Write change velocity
  1490. public bool WriteChangeVelocity(byte nNodeID, double dChangeVelocity)
  1491. {
  1492. return _WriteChangeVelocity(m_COMPort, nNodeID, dChangeVelocity);
  1493. }
  1494. // Read velocity move state
  1495. public bool ReadVelocityMoveState(byte nNodeID, ref ushort nVelocityMoveState)
  1496. {
  1497. return _ReadVelocityMoveState(m_COMPort, nNodeID, ref nVelocityMoveState);
  1498. }
  1499. // Read P2P move state
  1500. public bool ReadP2PMoveState(byte nNodeID, ref ushort nP2PMoveState)
  1501. {
  1502. return _ReadP2PMoveState(m_COMPort, nNodeID, ref nP2PMoveState);
  1503. }
  1504. // Read Q program segment number
  1505. public bool ReadQProgramSegmentNumber(byte nNodeID, ref ushort nQProgramSegmentNumber)
  1506. {
  1507. return _ReadQProgramSegmentNumber(m_COMPort, nNodeID, ref nQProgramSegmentNumber);
  1508. }
  1509. // Read position offset
  1510. public bool ReadPositionOffset(byte nNodeID, ref int nPositionOffset)
  1511. {
  1512. return _ReadPositionOffset(m_COMPort, nNodeID, ref nPositionOffset);
  1513. }
  1514. // Write position offset
  1515. public bool WritePositionOffset(byte nNodeID, int nPositionOffset)
  1516. {
  1517. return _WritePositionOffset(m_COMPort, nNodeID, nPositionOffset);
  1518. }
  1519. // Read running current
  1520. public bool ReadRunningCurrent(byte nNodeID, ref double dRunningCurrent)
  1521. {
  1522. return _ReadRunningCurrent(m_COMPort, nNodeID, ref dRunningCurrent);
  1523. }
  1524. // Write running current
  1525. public bool WriteRunningCurrent(byte nNodeID, double dRunningCurrent)
  1526. {
  1527. return _WriteRunningCurrent(m_COMPort, nNodeID, dRunningCurrent);
  1528. }
  1529. // Read electronic gearing
  1530. public bool ReadElectronicGearing(byte nNodeID, ref ushort nElectronicGearing)
  1531. {
  1532. return _ReadElectronicGearing(m_COMPort, nNodeID, ref nElectronicGearing);
  1533. }
  1534. // Write electronic gearing
  1535. public bool WriteElectronicGearing(byte nNodeID, ushort nElectronicGearing)
  1536. {
  1537. return _WriteElectronicGearing(m_COMPort, nNodeID, nElectronicGearing);
  1538. }
  1539. // Read pulse counter
  1540. public bool ReadPulseCounter(byte nNodeID, ref int nPulseCounter)
  1541. {
  1542. return _ReadPulseCounter(m_COMPort, nNodeID, ref nPulseCounter);
  1543. }
  1544. // Write pulse counter
  1545. public bool WritePulseCounter(byte nNodeID, int nPulseCounter)
  1546. {
  1547. return _WritePulseCounter(m_COMPort, nNodeID, nPulseCounter);
  1548. }
  1549. // Read analog position gain
  1550. public bool ReadAnalogPositionGain(byte nNodeID, ref ushort nAnalogPositionGain)
  1551. {
  1552. return _ReadAnalogPositionGain(m_COMPort, nNodeID, ref nAnalogPositionGain);
  1553. }
  1554. // Write analog position gain
  1555. public bool WriteAnalogPositionGain(byte nNodeID, ushort nAnalogPositionGain)
  1556. {
  1557. return _WriteAnalogPositionGain(m_COMPort, nNodeID, nAnalogPositionGain);
  1558. }
  1559. // Read analog threshold
  1560. public bool ReadAnalogThreshold(byte nNodeID, ref ushort nAnalogThreshold)
  1561. {
  1562. return _ReadAnalogThreshold(m_COMPort, nNodeID, ref nAnalogThreshold);
  1563. }
  1564. // Write analog threshold
  1565. public bool WriteAnalogThreshold(byte nNodeID, ushort nAnalogThreshold)
  1566. {
  1567. return _WriteAnalogThreshold(m_COMPort, nNodeID, nAnalogThreshold);
  1568. }
  1569. // Read analogoffset
  1570. public bool ReadAnalogOffset(byte nNodeID, ref ushort nAnalogOffset)
  1571. {
  1572. return _ReadAnalogOffset(m_COMPort, nNodeID, ref nAnalogOffset);
  1573. }
  1574. // Write analog offset
  1575. public bool WriteAnalogOffset(byte nNodeID, ushort nAnalogOffset)
  1576. {
  1577. return _WriteAnalogOffset(m_COMPort, nNodeID, nAnalogOffset);
  1578. }
  1579. // Read accumulator
  1580. public bool ReadAccumulator(byte nNodeID, ref int nAccumulator)
  1581. {
  1582. return _ReadAccumulator(m_COMPort, nNodeID, ref nAccumulator);
  1583. }
  1584. // Read user defined register
  1585. public bool ReadUserDefinedRegister(byte nNodeID, char chRegister, ref int nValue)
  1586. {
  1587. return _ReadUserDefinedRegister(m_COMPort, nNodeID, chRegister, ref nValue);
  1588. }
  1589. // Write user defined register
  1590. public bool WriteUserDefinedRegister(byte nNodeID, char chRegister, int nValue)
  1591. {
  1592. return _WriteUserDefinedRegister(m_COMPort, nNodeID, chRegister, nValue);
  1593. }
  1594. // Read brake release delay
  1595. public bool ReadBrakeReleaseDelay(byte nNodeID, ref double dBrakeReleaseDelay)
  1596. {
  1597. return _ReadBrakeReleaseDelay(m_COMPort, nNodeID, ref dBrakeReleaseDelay);
  1598. }
  1599. // Write brake release delay
  1600. public bool WriteBrakeReleaseDelay(byte nNodeID, double dBrakeReleaseDelay)
  1601. {
  1602. return _WriteBrakeReleaseDelay(m_COMPort, nNodeID, dBrakeReleaseDelay);
  1603. }
  1604. // Read brake engage delay
  1605. public bool ReadBrakeEngageDelay(byte nNodeID, ref double dBrakeEngageDelay)
  1606. {
  1607. return _ReadBrakeEngageDelay(m_COMPort, nNodeID, ref dBrakeEngageDelay);
  1608. }
  1609. // Write brake engage delay
  1610. public bool WriteBrakeEngageDelay(byte nNodeID, double dBrakeEngageDelay)
  1611. {
  1612. return _WriteBrakeEngageDelay(m_COMPort, nNodeID, dBrakeEngageDelay);
  1613. }
  1614. // Read analog filter gain
  1615. public bool ReadAnalogFilterGain(byte nNodeID, ref ushort nAnalogFilterGain)
  1616. {
  1617. return _ReadAnalogFilterGain(m_COMPort, nNodeID, ref nAnalogFilterGain);
  1618. }
  1619. // Write analog filter gain
  1620. public bool WriteAnalogFilterGain(byte nNodeID, ushort nAnalogFilterGain)
  1621. {
  1622. return _WriteAnalogFilterGain(m_COMPort, nNodeID, nAnalogFilterGain);
  1623. }
  1624. // Read alarm code
  1625. public bool ReadAlarmCode_M3(byte nNodeID, ref uint nAlarmCode)
  1626. {
  1627. return _ReadAlarmCode_M3(m_COMPort, nNodeID, ref nAlarmCode);
  1628. }
  1629. // Read status code
  1630. public bool ReadStatusCode_M3(byte nNodeID, ref uint nStatusCode)
  1631. {
  1632. return _ReadStatusCode_M3(m_COMPort, nNodeID, ref nStatusCode);
  1633. }
  1634. // Read driver board inputs
  1635. public bool ReadDriverBoardInputs_M3(byte nNodeID, ref ushort nInputsStatus)
  1636. {
  1637. return _ReadDriverBoardInputs_M3(m_COMPort, nNodeID, ref nInputsStatus);
  1638. }
  1639. // Read driver board outputs
  1640. public bool ReadDriverBoardOutputs_M3(byte nNodeID, ref ushort nOutputsStatus)
  1641. {
  1642. return _ReadDriverBoardOutputs_M3(m_COMPort, nNodeID, ref nOutputsStatus);
  1643. }
  1644. // Read encoder position
  1645. public bool ReadEncoderPosition_M3(byte nNodeID, ref int nEncoderPosition)
  1646. {
  1647. return _ReadEncoderPosition_M3(m_COMPort, nNodeID, ref nEncoderPosition);
  1648. }
  1649. // Read 2nd encoder position
  1650. public bool Read2ndEncoderPosition_M3(byte nNodeID, ref int nEncoderPosition)
  1651. {
  1652. return _Read2ndEncoderPosition_M3(m_COMPort, nNodeID, ref nEncoderPosition);
  1653. }
  1654. // Read immediate absolute position
  1655. public bool ReadImmediateAbsolutePosition_M3(byte nNodeID, ref int nImmediateAbsolutePosition)
  1656. {
  1657. return _ReadImmediateAbsolutePosition_M3(m_COMPort, nNodeID, ref nImmediateAbsolutePosition);
  1658. }
  1659. // Read immediate actual velocity
  1660. public bool ReadImmediateActualVelocity_M3(byte nNodeID, ref double dImmediateActualVelocity)
  1661. {
  1662. return _ReadImmediateActualVelocity_M3(m_COMPort, nNodeID, ref dImmediateActualVelocity);
  1663. }
  1664. // Read immediate target velocity
  1665. public bool ReadImmediateTargetVelocity_M3(byte nNodeID, ref double dImmediateTargetVelocity)
  1666. {
  1667. return _ReadImmediateTargetVelocity_M3(m_COMPort, nNodeID, ref dImmediateTargetVelocity);
  1668. }
  1669. // Read immediate drive temperature
  1670. public bool ReadImmediateDriveTemperature_M3(byte nNodeID, ref double dImmediateDriveTemperature)
  1671. {
  1672. return _ReadImmediateDriveTemperature_M3(m_COMPort, nNodeID, ref dImmediateDriveTemperature);
  1673. }
  1674. // Read immediate bus voltage
  1675. public bool ReadImmediateBusVoltage_M3(byte nNodeID, ref double dImmediateBusVoltage)
  1676. {
  1677. return _ReadImmediateBusVoltage_M3(m_COMPort, nNodeID, ref dImmediateBusVoltage);
  1678. }
  1679. // Read immediate position error
  1680. public bool ReadImmediatePositionError_M3(byte nNodeID, ref int nImmediatePositionError)
  1681. {
  1682. return _ReadImmediatePositionError_M3(m_COMPort, nNodeID, ref nImmediatePositionError);
  1683. }
  1684. // Read immediate analog input1 Value
  1685. public bool ReadImmediateAnalogInput1Value_M3(byte nNodeID, ref short nImmediateAnalogInputValue)
  1686. {
  1687. return _ReadImmediateAnalogInput1Value_M3(m_COMPort, nNodeID, ref nImmediateAnalogInputValue);
  1688. }
  1689. // Read immediate analog input2 Value
  1690. public bool ReadImmediateAnalogInput2Value_M3(byte nNodeID, ref short nImmediateAnalogInputValue)
  1691. {
  1692. return _ReadImmediateAnalogInput2Value_M3(m_COMPort, nNodeID, ref nImmediateAnalogInputValue);
  1693. }
  1694. // Read immediate analog Output1 Value
  1695. public bool ReadImmediateAnalogOutput1Value_M3(byte nNodeID, ref short nImmediateAnalogOutputValue)
  1696. {
  1697. return _ReadImmediateAnalogOutput1Value_M3(m_COMPort, nNodeID, ref nImmediateAnalogOutputValue);
  1698. }
  1699. // Write immediate analog Output1 Value
  1700. public bool WriteImmediateAnalogOutput1Value_M3(byte nNodeID, short nImmediateAnalogOutputValue)
  1701. {
  1702. return _WriteImmediateAnalogOutput1Value_M3(m_COMPort, nNodeID, nImmediateAnalogOutputValue);
  1703. }
  1704. // Read immediate analog Output2 Value
  1705. public bool ReadImmediateAnalogOutput2Value_M3(byte nNodeID, ref short nImmediateAnalogOutputValue)
  1706. {
  1707. return _ReadImmediateAnalogOutput2Value_M3(m_COMPort, nNodeID, ref nImmediateAnalogOutputValue);
  1708. }
  1709. // Read immediate analog Output2 Value
  1710. public bool WriteImmediateAnalogOutput2Value_M3(byte nNodeID, short nImmediateAnalogOutputValue)
  1711. {
  1712. return _WriteImmediateAnalogOutput2Value_M3(m_COMPort, nNodeID, nImmediateAnalogOutputValue);
  1713. }
  1714. // Read Q program line number
  1715. public bool ReadQProgramLineNumber_M3(byte nNodeID, ref ushort nQProgramLineNumber)
  1716. {
  1717. return _ReadQProgramLineNumber_M3(m_COMPort, nNodeID, ref nQProgramLineNumber);
  1718. }
  1719. // Read immediate current command
  1720. public bool ReadImmediateCurrentCommand_M3(byte nNodeID, ref short nImmediateCurrentCommand)
  1721. {
  1722. return _ReadImmediateCurrentCommand_M3(m_COMPort, nNodeID, ref nImmediateCurrentCommand);
  1723. }
  1724. // Read relative distance
  1725. public bool ReadRelativeDistance_M3(byte nNodeID, ref int nRelativeDistance)
  1726. {
  1727. return _ReadRelativeDistance_M3(m_COMPort, nNodeID, ref nRelativeDistance);
  1728. }
  1729. // Read sensor position
  1730. public bool ReadSensorPosition_M3(byte nNodeID, ref int nSensorPosition)
  1731. {
  1732. return _ReadSensorPosition_M3(m_COMPort, nNodeID, ref nSensorPosition);
  1733. }
  1734. // Read condition code
  1735. public bool ReadConditionCode_M3(byte nNodeID, ref ushort nConditionCode)
  1736. {
  1737. return _ReadConditionCode_M3(m_COMPort, nNodeID, ref nConditionCode);
  1738. }
  1739. // Read command mode
  1740. public bool ReadCommandMode_M3(byte nNodeID, ref ushort nCommandMode)
  1741. {
  1742. return _ReadCommandMode_M3(m_COMPort, nNodeID, ref nCommandMode);
  1743. }
  1744. // Read distance or position
  1745. public bool ReadDistanceOrPosition_M3(byte nNodeID, ref int nDistanceOrPosition)
  1746. {
  1747. return _ReadDistanceOrPosition_M3(m_COMPort, nNodeID, ref nDistanceOrPosition);
  1748. }
  1749. // Write distance or position
  1750. public bool WriteDistanceOrPosition_M3(byte nNodeID, int nDistanceOrPosition)
  1751. {
  1752. return _WriteDistanceOrPosition_M3(m_COMPort, nNodeID, nDistanceOrPosition);
  1753. }
  1754. // Read change distance
  1755. public bool ReadChangeDistance_M3(byte nNodeID, ref int nChangeDistance)
  1756. {
  1757. return _ReadChangeDistance_M3(m_COMPort, nNodeID, ref nChangeDistance);
  1758. }
  1759. // Write change distance
  1760. public bool WriteChangeDistance_M3(byte nNodeID, int nChangeDistance)
  1761. {
  1762. return _WriteChangeDistance_M3(m_COMPort, nNodeID, nChangeDistance);
  1763. }
  1764. // Read change velocity
  1765. public bool ReadChangeVelocity_M3(byte nNodeID, ref double dChangeVelocity)
  1766. {
  1767. return _ReadChangeVelocity_M3(m_COMPort, nNodeID, ref dChangeVelocity);
  1768. }
  1769. // Write change velocity
  1770. public bool WriteChangeVelocity_M3(byte nNodeID, double dChangeVelocity)
  1771. {
  1772. return _WriteChangeVelocity_M3(m_COMPort, nNodeID, dChangeVelocity);
  1773. }
  1774. // Read velocity move state
  1775. public bool ReadVelocityMoveState_M3(byte nNodeID, ref ushort nVelocityMoveState)
  1776. {
  1777. return _ReadVelocityMoveState_M3(m_COMPort, nNodeID, ref nVelocityMoveState);
  1778. }
  1779. // Read P2P move state
  1780. public bool ReadP2PMoveState_M3(byte nNodeID, ref ushort nP2PMoveState)
  1781. {
  1782. return _ReadP2PMoveState_M3(m_COMPort, nNodeID, ref nP2PMoveState);
  1783. }
  1784. // Read Q program segment number
  1785. public bool ReadQProgramSegmentNumber_M3(byte nNodeID, ref ushort nQProgramSegmentNumber)
  1786. {
  1787. return _ReadQProgramSegmentNumber_M3(m_COMPort, nNodeID, ref nQProgramSegmentNumber);
  1788. }
  1789. // Read Command current
  1790. public bool ReadCommandCurrent_M3(byte nNodeID, ref double dCommandCurrent)
  1791. {
  1792. return _ReadCommandCurrent_M3(m_COMPort, nNodeID, ref dCommandCurrent);
  1793. }
  1794. // Write Command current
  1795. public bool WriteCommandCurrent_M3(byte nNodeID, double dCommandCurrent)
  1796. {
  1797. return _WriteCommandCurrent_M3(m_COMPort, nNodeID, dCommandCurrent);
  1798. }
  1799. // Read Max current
  1800. public bool ReadMaximumCurrent_M3(byte nNodeID, ref double dMaximumCurrent)
  1801. {
  1802. return _ReadMaximumCurrent_M3(m_COMPort, nNodeID, ref dMaximumCurrent);
  1803. }
  1804. // Write Max current
  1805. public bool WriteMaximumCurrent_M3(byte nNodeID, double dMaximumCurrent)
  1806. {
  1807. return _WriteMaximumCurrent_M3(m_COMPort, nNodeID, dMaximumCurrent);
  1808. }
  1809. // Read electronic gearing
  1810. public bool ReadElectronicGearing_M3(byte nNodeID, ref uint nElectronicGearing)
  1811. {
  1812. return _ReadElectronicGearing_M3(m_COMPort, nNodeID, ref nElectronicGearing);
  1813. }
  1814. // Write electronic gearing
  1815. public bool WriteElectronicGearing_M3(byte nNodeID, uint nElectronicGearing)
  1816. {
  1817. return _WriteElectronicGearing_M3(m_COMPort, nNodeID, nElectronicGearing);
  1818. }
  1819. // Read pulse counter
  1820. public bool ReadPulseCounter_M3(byte nNodeID, ref int nPulseCounter)
  1821. {
  1822. return _ReadPulseCounter_M3(m_COMPort, nNodeID, ref nPulseCounter);
  1823. }
  1824. // Write pulse counter
  1825. public bool WritePulseCounter_M3(byte nNodeID, int nPulseCounter)
  1826. {
  1827. return _WritePulseCounter_M3(m_COMPort, nNodeID, nPulseCounter);
  1828. }
  1829. // Read analog position gain
  1830. public bool ReadAnalogPositionGain_M3(byte nNodeID, ref int nAnalogPositionGain)
  1831. {
  1832. return _ReadAnalogPositionGain_M3(m_COMPort, nNodeID, ref nAnalogPositionGain);
  1833. }
  1834. // Write analog position gain
  1835. public bool WriteAnalogPositionGain_M3(byte nNodeID, int nAnalogPositionGain)
  1836. {
  1837. return _WriteAnalogPositionGain_M3(m_COMPort, nNodeID, nAnalogPositionGain);
  1838. }
  1839. // Read analog position gain
  1840. public bool ReadAnalogVelocityGain_M3(byte nNodeID, ref double nAnalogVelocityGain)
  1841. {
  1842. return _ReadAnalogVelocityGain_M3(m_COMPort, nNodeID, ref nAnalogVelocityGain);
  1843. }
  1844. // Write analog position gain
  1845. public bool WriteAnalogVelocityGain_M3(byte nNodeID, double nAnalogVelocityGain)
  1846. {
  1847. return _WriteAnalogVelocityGain_M3(m_COMPort, nNodeID, nAnalogVelocityGain);
  1848. }
  1849. // Read analog position gain
  1850. public bool ReadAnalogTorqueGain_M3(byte nNodeID, ref double nAnalogTorqueGain)
  1851. {
  1852. return _ReadAnalogTorqueGain_M3(m_COMPort, nNodeID, ref nAnalogTorqueGain);
  1853. }
  1854. // Write analog position gain
  1855. public bool WriteAnalogTorqueGain_M3(byte nNodeID, double nAnalogTorqueGain)
  1856. {
  1857. return _WriteAnalogTorqueGain_M3(m_COMPort, nNodeID, nAnalogTorqueGain);
  1858. }
  1859. // Read analog threshold
  1860. public bool ReadAnalogThreshold1_M3(byte nNodeID, ref int nAnalogThreshold)
  1861. {
  1862. return _ReadAnalogThreshold1_M3(m_COMPort, nNodeID, ref nAnalogThreshold);
  1863. }
  1864. // Write analog threshold
  1865. public bool WriteAnalogThreshold1_M3(byte nNodeID, int nAnalogThreshold)
  1866. {
  1867. return _WriteAnalogThreshold1_M3(m_COMPort, nNodeID, nAnalogThreshold);
  1868. }
  1869. // Read analog threshold
  1870. public bool ReadAnalogThreshold2_M3(byte nNodeID, ref int nAnalogThreshold)
  1871. {
  1872. return _ReadAnalogThreshold2_M3(m_COMPort, nNodeID, ref nAnalogThreshold);
  1873. }
  1874. // Write analog threshold
  1875. public bool WriteAnalogThreshold2_M3(byte nNodeID, int nAnalogThreshold)
  1876. {
  1877. return _WriteAnalogThreshold2_M3(m_COMPort, nNodeID, nAnalogThreshold);
  1878. }
  1879. // Read analogoffset
  1880. public bool ReadAnalogOffset1_M3(byte nNodeID, ref int nAnalogOffset)
  1881. {
  1882. return _ReadAnalogOffset1_M3(m_COMPort, nNodeID, ref nAnalogOffset);
  1883. }
  1884. // Write analog offset
  1885. public bool WriteAnalogOffset1_M3(byte nNodeID, int nAnalogOffset)
  1886. {
  1887. return _WriteAnalogOffset1_M3(m_COMPort, nNodeID, nAnalogOffset);
  1888. }
  1889. // Read analogoffset
  1890. public bool ReadAnalogOffset2_M3(byte nNodeID, ref int nAnalogOffset)
  1891. {
  1892. return _ReadAnalogOffset2_M3(m_COMPort, nNodeID, ref nAnalogOffset);
  1893. }
  1894. // Write analog offset
  1895. public bool WriteAnalogOffset2_M3(byte nNodeID, int nAnalogOffset)
  1896. {
  1897. return _WriteAnalogOffset2_M3(m_COMPort, nNodeID, nAnalogOffset);
  1898. }
  1899. // Read accumulator
  1900. public bool ReadAccumulator_M3(byte nNodeID, ref int nAccumulator)
  1901. {
  1902. return _ReadAccumulator_M3(m_COMPort, nNodeID, ref nAccumulator);
  1903. }
  1904. // Read user defined register
  1905. public bool ReadUserDefinedRegister_M3(byte nNodeID, char chRegister, ref int nValue)
  1906. {
  1907. return _ReadUserDefinedRegister_M3(m_COMPort, nNodeID, chRegister, ref nValue);
  1908. }
  1909. // Write user defined register
  1910. public bool WriteUserDefinedRegister_M3(byte nNodeID, char chRegister, int nValue)
  1911. {
  1912. return _WriteUserDefinedRegister_M3(m_COMPort, nNodeID, chRegister, nValue);
  1913. }
  1914. // Read brake release delay
  1915. public bool ReadBrakeReleaseDelay_M3(byte nNodeID, ref double dBrakeReleaseDelay)
  1916. {
  1917. return _ReadBrakeReleaseDelay_M3(m_COMPort, nNodeID, ref dBrakeReleaseDelay);
  1918. }
  1919. // Write brake release delay
  1920. public bool WriteBrakeReleaseDelay_M3(byte nNodeID, double dBrakeReleaseDelay)
  1921. {
  1922. return _WriteBrakeReleaseDelay_M3(m_COMPort, nNodeID, dBrakeReleaseDelay);
  1923. }
  1924. // Read brake engage delay
  1925. public bool ReadBrakeEngageDelay_M3(byte nNodeID, ref double dBrakeEngageDelay)
  1926. {
  1927. return _ReadBrakeEngageDelay_M3(m_COMPort, nNodeID, ref dBrakeEngageDelay);
  1928. }
  1929. // Write brake engage delay
  1930. public bool WriteBrakeEngageDelay_M3(byte nNodeID, double dBrakeEngageDelay)
  1931. {
  1932. return _WriteBrakeEngageDelay_M3(m_COMPort, nNodeID, dBrakeEngageDelay);
  1933. }
  1934. // Read analog filter gain
  1935. public bool ReadAnalogFilterGain1_M3(byte nNodeID, ref ushort nAnalogFilterGain)
  1936. {
  1937. return _ReadAnalogFilterGain1_M3(m_COMPort, nNodeID, ref nAnalogFilterGain);
  1938. }
  1939. // Write analog filter gain
  1940. public bool WriteAnalogFilterGain1_M3(byte nNodeID, ushort nAnalogFilterGain)
  1941. {
  1942. return _WriteAnalogFilterGain1_M3(m_COMPort, nNodeID, nAnalogFilterGain);
  1943. }
  1944. // Read analog filter gain
  1945. public bool ReadAnalogFilterGain2_M3(byte nNodeID, ref ushort nAnalogFilterGain)
  1946. {
  1947. return _ReadAnalogFilterGain2_M3(m_COMPort, nNodeID, ref nAnalogFilterGain);
  1948. }
  1949. // Write analog filter gain
  1950. public bool WriteAnalogFilterGain2_M3(byte nNodeID, ushort nAnalogFilterGain)
  1951. {
  1952. return _WriteAnalogFilterGain2_M3(m_COMPort, nNodeID, nAnalogFilterGain);
  1953. }
  1954. // Write broadcast command
  1955. public bool WriteBroadcastCommand(byte nNodeIDCount, byte[] aNodeIDArr, byte nFunctionCode)
  1956. {
  1957. bool ret = _WriteBroadcastCommand(m_COMPort, nNodeIDCount, aNodeIDArr, nFunctionCode);
  1958. return ret;
  1959. }
  1960. // Execute multi-axes linear interpolation move
  1961. public bool ExecuteLinearInterpolationMove(byte nNodeIDCount, byte[] aNodeIDArr, int[] aPosArr, uint nMaxLineSpeed, uint nAccelTimeInMs, bool bRelMove = true, bool bValidParamLimit = true)
  1962. {
  1963. bool ret = _ExecuteLinearInterpolationMove(m_COMPort, nNodeIDCount, aNodeIDArr, aPosArr, nMaxLineSpeed, nAccelTimeInMs, bRelMove, bValidParamLimit);
  1964. return ret;
  1965. }
  1966. #endregion
  1967. }
  1968. }