| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using FluentFTP;
- using GSG.NET.Logging;
- using GSG.NET.ObjectBase;
- using GSG.NET.TCP;
- using GSG.NET.Utils;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace VehicleControlSystem.Managers
- {
- /// <summary>
- /// 아날로그 입력 정보를 종합하여 로그로 남기는 역할
- /// FTP 를 이용하여 파일 전송
- /// </summary>
- class PhysicalCheckupLogger : SingletonBase<PhysicalCheckupLogger>, IDisposable
- {
- Logger frontlogger = Logger.GetLogger( "PhysicalCheckup_Front" );
- Logger rearlogger = Logger.GetLogger( "PhysicalCheckup_Rear" );
- Logger logger = Logger.GetLogger();
- TcpConnector h = new TcpConnector();
- const byte CR = 0x0d;
- public string PLCAddress { get; set; } = "192.168.0.20";
- public int PLCPort { get; set; } = 8501;
- public string PLCFolderName { get; set; }
- public string FTPFolderName { get; set; }
- private PhysicalCheckupLogger()
- {
- }
- public void Dispose()
- {
- this.h.CloseSocket();
- }
- public void FrontWheelLogging( string speed, string torque, string RPM, string LoadFactor, string MCR ) => frontlogger.I( $"Speed : {speed} / Torque : {torque} / RPM : {RPM} / LoadFactor : {LoadFactor} / MCR : {MCR}" );
- public void RearWheelLoggging( string speed, string torque, string RPM, string LoadFactor, string MCR ) => rearlogger.I( $"Speed : {speed} / Torque : {torque} / RPM : {RPM} / LoadFactor : {LoadFactor} / MCR : {MCR}" );
- public async Task UploadPhysicalCheckupLogAsync()
- {
- var token = new CancellationToken();
- using ( var ftp = new FtpClient( "192.168.127.188" ) )
- {
- await ftp.ConnectAsync( token );
- // upload a folder and all its files
- await ftp.UploadDirectoryAsync( @"C:\LOG\FTP\", @"/DriveLog", FtpFolderSyncMode.Update );
- // upload a folder and all its files, and delete extra files on the server
- //ftp.UploadDirectory( @"C:\website\assets\", @"/public_html/assets", FtpFolderSyncMode.Mirror );
- //ToDo: Delete Files
- }
- }
- public void DownloadPLCLog()
- {
- using ( var ftp = new FtpClient( "192.168.0.20", "KVID", "1234" ) )
- {
- ftp.Connect();
- // download a folder and all its files
- ftp.DownloadDirectory( @"C:\LOG\FTP\", @"/0_CARD/log0/", FtpFolderSyncMode.Update );
- // download a folder and all its files, and delete extra files on disk
- //await ftp.DownloadDirectoryAsync( @"C:\website\dailybackup\", @"/public_html/", FtpFolderSyncMode.Mirror );
- //ftp.DeleteFile( "/full/or/relative/path/to/file" );
- }
- }
- public void FTPServerDeleteFile()
- {
- using ( var ftp = new FtpClient( "192.168.0.20", "KV", "1234" ) )
- {
- ftp.Connect();
- ftp.DeleteDirectory( "/0_CARD/log0/" );
- }
- }
- public void Connecte()
- {
- h.Connect( new TcpComm
- {
- Active = true,
- Ip = "192.168.0.20",
- PortNo = 8501,
- } );
- }
- /// <summary>
- /// 주행 시작 시 진단 PLC Bit On
- /// </summary>
- /// <returns></returns>
- public bool SetPLCStartDrive()
- {
- try
- {
- if ( !h.Connected )
- {
- h.Connect( new TcpComm
- {
- Active = true,
- Ip = "192.168.0.20",
- PortNo = 8501,
- } );
- }
- if ( !h.Connected )
- return false;
- var mb = new MemoryBuffer();
- mb.AppendAscii( "WR MR100 1" );
- mb.Append( CR );
- this.h.WriteFlush( mb.ToBytes );
- //h.CloseSocket();
- }
- catch ( Exception e )
- {
- h.CloseSocket();
- logger.E( $"[PLC] - Set Value Connection Error {e}" );
- return false;
- }
- return true;
- }
- /// <summary>
- /// 주행 정지 시 진단 PLC Bit Off
- /// </summary>
- /// <returns></returns>
- public bool ResetPLCStartDrive()
- {
- try
- {
- if ( !h.Connected )
- {
- h.Connect( new TcpComm
- {
- Active = true,
- Ip = "192.168.0.20",
- PortNo = 8501,
- } );
- }
- if ( !h.Connected )
- return false;
- var mb = new MemoryBuffer();
- mb.AppendAscii( "WR MR100 0" );
- mb.Append( CR );
- this.h.WriteFlush( mb.ToBytes );
- //h.CloseSocket();
- }
- catch ( Exception e )
- {
- h.CloseSocket();
- logger.E( $"[PLC] - Reset Value Connection Error {e}" );
- return false;
- }
- return true;
- }
- }
- }
|