Fanuc.cs 2.6 KB

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