Fanuc.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. namespace IMCS_CCS.Utils.DeviceProtocol
  6. {
  7. public class Fanuc : Focas1
  8. {
  9. public static ushort h;
  10. private static short getdtailerr(ushort handle, Fanuc.ODBERR odberr)
  11. {
  12. return Fanuc.cnc_getdtailerr(handle, odberr);
  13. }
  14. private static short upstart(ushort handle, short type, int startno, int endno)
  15. {
  16. return cnc_upstart3(handle, type, startno, endno);
  17. }
  18. private static short uplod(ushort handle, int length, char[] databuf)
  19. {
  20. return cnc_upload3(handle, ref length, databuf);
  21. }
  22. private static short upend(ushort handle)
  23. {
  24. return cnc_upend3(handle);
  25. }
  26. public static short upload(ushort handle, short type, int no, ref string data, Fanuc.ODBERR odberr)
  27. {
  28. int startno = no; int endno = no;
  29. int length = 256; char[] databuf = new char[256];
  30. short ret = upstart(handle, type, startno, endno);
  31. if (ret == Fanuc.EW_OK)
  32. {
  33. string temp = "";
  34. while (true)
  35. {
  36. ret = uplod(handle, length, databuf);
  37. temp = new string(databuf);
  38. int one = temp.Length;
  39. if (ret == (short)Fanuc.focas_ret.EW_BUFFER)
  40. {
  41. continue;
  42. }
  43. if (ret == Fanuc.EW_OK)
  44. {
  45. temp = temp.Replace("\0", "");
  46. data += temp;
  47. string lastchar = temp.Substring(temp.Length - 1, 1);
  48. if (lastchar == "%")
  49. {
  50. break;
  51. }
  52. }
  53. else
  54. {
  55. if (odberr != null)
  56. {
  57. getdtailerr(handle, odberr);
  58. }
  59. break;
  60. }
  61. }
  62. if (ret == 0)
  63. {
  64. ret = upend(handle);
  65. return ret;
  66. }
  67. else
  68. {
  69. upend(handle);
  70. return ret;
  71. }
  72. }
  73. else
  74. {
  75. upend(handle);
  76. return ret;
  77. }
  78. }
  79. }
  80. }