CarCamDevice.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using log4net;
  2. using System;
  3. using System.IO;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace DeviceCenter
  7. {
  8. class CarCamDevice : Device
  9. {
  10. public static readonly ILog log = LogManager.GetLogger("DeviceCenter");
  11. private int _userId;
  12. public int userId
  13. {
  14. get
  15. {
  16. return _userId;
  17. }
  18. }
  19. public CarCamDevice()
  20. {
  21. this.type = DeviceType.CAR_CAM;
  22. }
  23. public override async void Init()
  24. {
  25. status = DeviceStatus.CONNECTING;
  26. await Task.Run(() =>
  27. {
  28. _userId = CarCamSDK.Net_AddCamera(ip);
  29. int iRet1 = CarCamSDK.Net_ConnCamera(_userId, 30000, 10);
  30. if (iRet1 != 0)
  31. {
  32. CarCamSDK.Net_DelCamera(_userId);
  33. status = DeviceStatus.FAIL;
  34. message = "连接相机失败";
  35. }
  36. else
  37. {
  38. CarCamSDK.Net_RegOffLineClient(_userId);
  39. status = DeviceStatus.CONNECTED;
  40. }
  41. });
  42. }
  43. public override void dispose()
  44. {
  45. throw new NotImplementedException();
  46. }
  47. public int onGetCarPlate(int tHandle, uint uiImageId, ref CarCamSDK.T_ImageUserInfo2 tImageInfo, ref CarCamSDK.T_PicInfo tPicInfo)
  48. {
  49. string strTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd_HH_mm_ss_fff");
  50. log.Info("检测到车牌信息\n");
  51. //车辆图像
  52. if (tImageInfo.ucViolateCode == 0)
  53. {
  54. string szLprResult = Encoding.Default.GetString(tImageInfo.szLprResult).Replace("\0", "");
  55. log.Info("车牌:" + szLprResult);
  56. string strVehicleBrand = System.Text.Encoding.Default.GetString(tImageInfo.strVehicleBrand).Replace("\0", "");
  57. log.Info("车型:" + strVehicleBrand);
  58. string vehicleType = VehicleUtil.getVehicleType(tImageInfo.ucVehicleSize);//车辆类型
  59. log.Info("车辆类型:" + vehicleType);
  60. string vehicleColor = VehicleUtil.getColor(tImageInfo.ucPlateColor);//车牌颜色
  61. log.Info("颜色:" + vehicleColor);
  62. string path = AppDomain.CurrentDomain.BaseDirectory + "image";
  63. if (!Directory.Exists(path))
  64. {
  65. Directory.CreateDirectory(path);
  66. }
  67. string strImageFile1 = VehicleUtil.savePanoramaPic(path, ref tPicInfo, 1);
  68. string strImageFile2 = VehicleUtil.savePanoramaPic(path, ref tPicInfo, 2); ;
  69. }
  70. return 0;
  71. }
  72. }
  73. }